我有一個問題,我的Laravel 5.2路由/控制器之一,特別是我得到Controller method not found.
Laravel 5.2控制器的方法沒有找到,但出現在工匠路線:列表
路線的錯誤:
Route::get('guest/shop/{product}', '[email protected]')->name('guest.shop.show');
控制器和控制方法:
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);
}
}
事情進行調試時,我已經做了:
- 然
php artisan route:list
和確認路線,控制器和中間件所有匹配起來 - 然
composer dumpautoload
- 到routes.php文件的頂部移到路線
- 移到抽象ShopController的方法分爲GuestShopController和改變GuestShopController延伸到Laravel默認控制器
根相對URL我去的是'/客/店/魁eius-ET-阿梅特-UT-ET-tempora'。拉丁部分是通過faker播種的slu slu。 – Ben
另外,我沒有使用UserController。 – Ben
是的我的意思是GuestShopController不是UserController – tnash