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");
}
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.
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
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>
Related
I was working on a project earlier on and ran into this error
Symfony\Component\Routing\Exception\RouteNotFoundException
Route [/math/{ $math->id }/question] not defined.
Here's my route:
Route::post('/math/{math}/question', [App\Http\Controllers\QuestionController::class, 'store'])->name('/math/{math}/question')->middleware('auth');
Blade File Route:
<form action="{{ route('/math/{ $math->id }/question') }}" method="post">
Controller:
public function create(Math $math)
{
return view('question.create', compact('math'));
}
What am I doing wrong?
1st, route() uses the ->name() parameter.
2nd, math/{math}/question is not a good route name.
Change your name to something sensical, like math_question, then fix your code:
Route::post('/math/{math}/question', [App\Http\Controllers\QuestionController::class, 'store'])->name('math_question')->middleware('auth');
Then:
<form action="{{ route('math_question', ['math' => $math->id]) }}" method="post">
Route::post('/math/{math}/question', [App\Http\Controllers\QuestionController::class, 'store'])->name('mathQuestion')->middleware('auth');
<form action="{{ route('mathQuestion', ['math' => $math->id]) }}" method="post">
This is what my code looks like
Route:
Route::put('/articles/{$article}', 'ArticlesController#update');
Controller:
public function update($id){
$article=Article::find($id);
$article ->title = request('title');
$article->excerpt=request('excerpt');
$article->body=request('body');
$article->save();
return redirect('/articles/'. $article->id);
}
Blade:
<form method="POST" action="/articles/{{$article->id}}" >
#csrf
#method('PUT')
And everytime I try to submit an update I get this:
The PATCH method is not supported for this route. Supported methods: GET, HEAD.
I'm currently stuck on this one.
Try this
<form action="/articles/{{$article->id}}" method="POST">
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
and the route
Route::put('/articles/{article}', 'ArticlesController#update');
It's better to do:
in routing
Route::put('/articles/{id}', 'ArticlesController#update')->name('articles.update');
in controller
public function update(Request $request, $id)
{
// logic
}
don't forget to use Request in controller
in blade
it's better to use naming for routes but it might be a problem in your action
<form method="POST" action="{{ route('articles.update', $article->id) }}">
simple way using blade
<form action="/articles/{{$article->id}}" method="POST">
#method('put')
#csrf
</form>
project is laravel 5.6. My project has 2 routes:
web.php
Route::get('testa', 'HomeController#showTestForm')->name('test');
Route::post('testa', 'HomeController#doTest');
HomeController :
public function showTestForm()
{
Log::warning('from showTestForm');
return view('test');
}
.public function doTest(Request $request)
{
Log::info('from doTest');
// return Input::all();
return view('test', [
'input' => implode(', ', Input::all()),
]);
}
test.blade.php
<form method="post" action="{{ route('test') }}">
#csrf
<input type="text" name="inputvalue">
<button type="submit" class="btn btn-primary">
merge
</button>
</form>
<div>Result</div>
#if(isset($input))
{{$input}}
#endif
Why is working post on route('test') ?
Thank you.
The reason that route('test') works even though your form is a POST request is because route() is just a helper function to generate a url and your GET and POST routes both use the same url.
You've specified in your form to make a post request and it's going to send it to the url provided (which will be the same as your GET request in this case).
Edit:
Route::post('testa', 'HomeController#doTest')->name('postTest');
and then use
<form method="post" action="{{ route('postTest') }}">
Hope this will work
It is because you'are calling the wrong route.
Change :
<form method="post" action="{{ route('test') }}">
to :
<form method="post" action="{{ url('/testa') }}">
or follow the previous answer steps (name the post route then call it)
I believe from the OP they are not understanding how the same route can accept both a GET request and a POST request.
The difference is in how the server receives the data.
Have a read: HTTP Requests
I have a view whit the next code:
<h1>Edicion</h1>
#foreach ($usuarios as $usu)
<h4>{{$usu->nombre}}</h4>
editar
#endforeach
This route:
Route::resource('/prurequests','PruebasControllers\PrurequestsController');
The method edit:
public function edit($slug)
{
$usuario = Usuario2::where('slug','=',$slug)->firstOrFail();
return view('vistaspruebas.edit', compact('usuario'));
}
In this route my URL is:
/public/prurequests/vaca/edit
The code in this view 'vistaspruebas.edit' is:
<form action="prurequests/suma" method="POST">
#method('PUT')
#csrf
<label for="nombre">ingrese nombre</label>
<input type="text" name="nombre" value="{{$usuario->slug}}">
<br />
<button type="submit" name="" value="submit">Actualiza</button>
</form>
instead of looking for this route: "prurequests/suma " Laravel look for /public/prurequests/vaca/prurequests/suma
someone knows why after the tag and call other route it removes 'edit' and change it by and other route i put here?
Please use action() helper method in your form as the following:
<form action="{{ action('Controller#method') }}" method="POST">
Or you can use the route helper method as the following:
<form action="{{ route('route_name') }}" method="POST">
Also you can use url() helper if you want to use a given path:
<form action="{{ url('path_here') }}" method="POST">
I am trying to set a Password reminder in restful way. (Following this tutorial http://laravel.com/docs/4.2/security#password-reminders-and-reset but trying to do it in restful way)
The route looks like this,
Route::group(array('prefix' => 'api/v1'), function(){
Route::resource(
'password', 'RemindersController',
array(
'only' => array('store', 'show', 'update')
)
);
});
RemindersController starts as,
public function update()
{
}
The password reset url is
http://192.x.x.x:8000/api/v1/password/3adb8b0454144ef5aeaa333faa5c575bd833e03d
From this url loading reset.blade as follows,
<form action="{{ action('RemindersController#update') }}" method="PUT"
...
<input type="submit" value="Reset Password"> </form>
But when loading this page, the form action seems to have some issues, the action url does not seem to be right.
<form action="http://192.x.x.x:8000/api/v1/password/%7Bpassword%7D" method="PUT">
What is the right way to provide action property in the form for this? How can I pass the password reset details to 'update' method in Reminder controller?
In the mentioned tutuorial it is like
action="{{ action('RemindersController#postReset') }}" method="POST"
What will change when using the restful resource way?
Got it right by following the suggestion from this site with the following modification,
<form action="{{ URL::to('api/v1/password/update') }}" method="POST">
<input name="_method" type="hidden" value="PUT">