I recently upgraded from laravel 5.1 to 5.2 and now I'm getting an error of Missing required parameters for [Route: example.destroy] [URI: example/{args}].
The error occurs here:
<form class="form-horizontal" action="<?php echo route('example.destroy'); ?>" method="post"> on the action attribute of the form.
Here's how the route was registered on the route.php
Route::resource('example', 'ExampleController');
When I was in 5.1, there was no error with this line. Just went I upgrade to 5.2, it now occurs.
The functionality of this is that it will allow user to delete multiple entries by checking the checkboxes that they wish to be deleted. Then upon submit, it will redirect to the destroy method on the controller.
You can try the following
<form class="form-horizontal" action="<?php echo
url('example'); ?>" method="post">
Route::post('example', 'ExampleController#destroy');
I had the same problem when updating my app to Laravel 5.2.
Apparently, Laravel 5.2 require a valid Route to "destroy resource", ex:
/my-route/item-to-destroy/{id}
Here, in our apps I'm putting an "{id} = 0" or "{id} = null", at the end of each route (when calling a "route destroy" that is not yet ready).
In your case, it would be similar to that:
<form action="<?php echo route('example_route.destroy', ['id'=>0]); ?>" method="post">
or, declare a valid resource id:
<form action="<?php echo route('example_route.destroy', ['id'=>$object->id]); ?>" method="post">
Try with this:
<form class="form-horizontal" action="<?php echo route('example.destroy', $record->id); ?>" method="post">
or Laravel way:
{!! Form::open(['route' => ['example.destroy', $record->id],
'method' => 'delete']) !!}
{!! Form::close() !!}
Related
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>
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 am using a resource Laravel route defined by the following line in my routes.php :
Route::resource('test', 'App\Controllers\Teacher\TestController', ['only' => ['index', 'create', 'destroy']]);
The index method works fine. In the template of index I have created a form in order to remove an item of the list.
<form method="DELETE" action="{{ URL::action('App\Controllers\Teacher\TestController#destroy', $audit->id ) }}">
<input type="submit" value="Remove" />
</form>
The URL is correctly generated by Laravel but when I post this form I get the following error :
exception 'Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException' in /var/www/project/bootstrap/compiled.php:5365
I have already try to change DELETE by POST in the method attribute of my form but it doesn't work.
I also read this post but it doesn't help me : MethodNotAllowedHttpException on resource defined method Laravel-4
When you manually create your form you should use POST as method, and use _method input with delete value this way:
<form method="POST" action="{{ URL::action('App\Controllers\Teacher\TestController#destroy', $audit->id ) }}">
<input type="hidden" name="_method" value="DELETE" />
<input type="submit" value="Remove" />
</form>
Reference in Laravel documentation for form method spoofing
Try this:
<form action="/test" ....>
im trying to buld a complate form using laravel but i cant make this right :
<form class="form-horizontal">
<fieldset>
{{Form::open(array('url'=>'register'))}}
but clearly this does not do anything with my data base so i want this :
<form class="form-horizontal" action={{ url('our/target/route') }}" method="post">
but when i do this my form is not horizontal anymore and becomes something un watchable
so what is the problem ?
Now you have two <form>
Try this:
{{ Form::open(array('url' => 'register', 'class' => 'form-horizontal')) }}
<fieldset>
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">