I have an issue with one of my Laravel 5.2 routes/controllers, specifically I get the error of Controller method not found.
Route:
Route::get( 'guest/shop/{product}', 'GuestShopController@show' )->name( 'guest.shop.show' );
Controller and method:
class GuestShopController extends ShopController {
public function __construct( ) {
$this->middleware( 'guest' );
}
}
abstract class ShopController extends Controller {
protected function singularProductData( $product ) {
$thumbnails = $product->thumbnails();
return [
'product' => $product,
'thumbnails' => $thumbnails,
'main_thumbnail' => head( $thumbnails ),
];
}
protected function getProducts() {
return Cache::remember(
'products',
3600,
function () {
return Product::active()->get();
}
);
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index() {
return view( 'pages.shop.index' )->with(
[
'products' => $this->getProducts(),
'organisation' => request()->attributes->get( 'organisation' ),
]
);
}
/**
* Display the specified product.
*
* @param string $slug
* @param null $product
*
* @return \Illuminate\Http\Response
*/
public function show( $slug, $product = null ) {
if( ! is_a( $product, Product::class ) ) {
$product = Product::active()->where( 'slug', $slug )->firstOrFail();
}
return view( 'pages.shop.product' )->with( $this->singularProductData( $product ) );
}
/**
* Display the specified product modal.
*
* @param int $id
*
* @return \Illuminate\Http\Response
*/
public function modal( $id ) {
$product = Product::active()->findOrFail( $id );
if( request()->ajax() ) {
return view( '_partials.shop.modal-content' )->with( $this->singularProductData( $product ) );
}
return $this->show( $product->slug, $product );
}
}
Things I've already done when debugging:
- Ran
php artisan route:listand confirmed route, controller and middleware all match up - Ran
composer dumpautoload - Moved route to top of routes.php
- Moved methods of abstract ShopController into GuestShopController and changed extends of GuestShopController to Laravel default Controller
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1RkJMIy
via IFTTT
Aucun commentaire:
Enregistrer un commentaire