The storeClientRequest
Cannot be triggered, is there any mistake here ? When I hit submit, the page shows 404 Not found
Form
<form class="needs-validation" novalidate method="POST" action="store-client-request/{{ Auth::user()->id }}">
@csrf
//////content
</form>
Route
Route::group(['prefix'=>'user', 'middleware'=>['isUser','auth']], function(){
Route::post('store-client-request/{user}', [UserController::class, 'storeClientRequest']);
});
Controller
function storeClientRequest(User $user)
{
dd('hi');
return redirect()->back()->with("message", "Create request successfully");
}
CodePudding user response:
Add a name to your route :
Route::post('store-client-request/{user}', [UserController::class, 'storeClientRequest'])->name("store.client.request");
Make sure you run
php artisan optimize
Reference your route by name in the opening form tag :
action="{{ route('store.client.request', ['user' => Auth::user()->id]) }}">
That way, it doesn't matter (a) what the route prefix is (that it looks like you've forgotten to include) or (b) if the address to the route changes later down the line - the {{ route() }} blade directive will always pull in the correct URL, along with the relevant parameters.
CodePudding user response:
As I see through you code: your full route is /user/store-client-request/{user}
Therefore in you action you should put
<form class="needs-validation" novalidate method="POST" action="/user/store-client-request/{{ Auth::user()->id }}">
@csrf
//////content
CodePudding user response:
In your Route there is /user/store-client-request/{user}
So Add this in your Action
<form class="needs-validation" novalidate method="POST" action="/user/store-client-request/{{ Auth::user()->id }}">
</form>