简体   繁体   English

找不到路线 laravel

[英]Route not found laravel

I'm getting an error 404|Not found , while the route is existing and the debugger is on I have cleared route cache but still showing the error, when I php artisan route:list it shows POST | products/{product}/favourites | product.fav.store | App\Http\Controllers\HomeController@store我收到错误 404 POST | products/{product}/favourites | product.fav.store | App\Http\Controllers\HomeController@store 404|Not found cleared route cachephp artisan route:list存在且调试器已打开时POST | products/{product}/favourites | product.fav.store | App\Http\Controllers\HomeController@store POST | products/{product}/favourites | product.fav.store | App\Http\Controllers\HomeController@store How can I solve this? POST | products/{product}/favourites | product.fav.store | App\Http\Controllers\HomeController@store我该如何解决这个问题?

controller controller

public function store(Request $request, Product $product)
{
    $request->user()->favouriteProducts()->syncWithoutDetaching([$product->id]);

    return back();
}

Blade

<span class="pull-right">
<a href="" onclick="event.preventDefault(); document.getElementById('product-fav-form').submit();">Add to Fav</a>

<form id="product-fav-form" class="hidden" action="   {{route('product.fav.store', $product) }}" method="POST">
{{ csrf_field()}}
</form>
</span>

Route路线

 Route::post('/products/{product}/favourites', 'HomeController@store')->name('product.fav.store');

You should change your route like.你应该改变你的路线。

<form action="{{ route('product.fav.store', ['product' => $product->id]) }}" >

Try this,尝试这个,

 <form method="POST" action="{{ route('product.fav.store', ['product' => $product->id]) }}">

Change the controller function更改 controller function

public function store(Request $request,$product)
{
$request->user()->favouriteProducts()->syncWithoutDetaching($product);

return back();
}

Try this:尝试这个:

<form id="product-fav-form" class="hidden" action="{{route('product.fav.store', $product->name)}}" method="POST">

controller: controller:

public function store(Request $request, $name) {
    $request->user()->favouriteProducts()->syncWithoutDetaching($name);
    return back();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM