I have defined a resourceful route like this:
Route::resource('user/info/experience', 'ExperienceController');
And the following is what i have used in my form:
{!! Form::open([
'route'=>'user.info.experience.store',
'method' => 'post',
]
) !!}
Now it's giving me the
Route [user.info.experience] not defined
What am I doing wrong?
There was no problem with the route definition or in from. The problem was that there was another call to user.info.experience in my view which didn't exist. So I corrected that call and the error is gone.
try this:
Routes
Route::resource('user/info/experience', 'ExperienceController');
Form
{!! Form::open([
'route'=>'user/info/experience',
'method' => 'post',
]
) !!}
or use alias:
Routes
Route::post('user/info/experience', array('as' => 'experience', 'uses' => 'ExperienceController#functionName'));
Form
{!! Form::open([
'route'=>'experience',
'method' => 'post',
]
) !!}
try Route::resource('user.info.experience', 'ExperienceController');
Related
In my laravel site, I have a page with an existing form submission (working) and I'm trying to add another form but the refresh on submit goes to a blank page
I have a route set for the POST of each form, but the problem comes from the fact that I have 2 POSTs to the same effective url 'Route::post('user'
Each POST calls a different function in the controller and I need both forms to be on the same page/url (manager/user) but I'm not sure how to change this so that they both work here.
If I comment out the route for manager.user.create, then the store submission works just fine again.
Route::post('user', 'user\userManagerController#store')
->name('manager.user');
Route::post('user', 'user\userManagerController#create')
->name('manager.user.create');
{!! Form::open(array('method' => 'POST', 'url' => route('manager.user'))) !!}
{!! Form::open(array('method' => 'POST', 'url' => route('manager.user.create'))) !!}
You can't define two endpoints with the same verb and URI.
You may try this:
Route::post('user', 'user\userManagerController#store')
->name('manager.user');
Route::post('anotherURI', 'user\userManagerController#create')
->name('manager.user.create');
{!! Form::open(array('method' => 'POST', 'url' => route('manager.user'))) !!}
{!! Form::open(array('method' => 'POST', 'url' => route('manager.user.create')))
stuck with this error any help would be much appreciated. The error I'm getting is below:
Action App\Http\Controllers\PostsController#destroy not defined. (View: C:\xampp\htdocs\lsapp\resources\views\posts\show.blade.php)
I do have the "destroy" method in the PostsController and using the latest vision of Laravel.
{!!Form::open(['action' => ['PostsController#destroy', $post->id], 'method' => 'POST', 'class' => 'pull-right'])!!}
{{Form::hidden('_method', 'DELETE')}}
{{Form::submit('Delete', ['class' => 'btn btn-danger'])}}
{!!Form::close()!!}
Try this.
I changed ACTION to URL.
{!!Form::open(['url' => ['posts', $post->id], 'method' => 'POST', 'class' => 'pull-right'])!!}
{{Form::hidden('_method', 'DELETE')}}
{{Form::submit('Delete', ['class' => 'btn btn-danger'])}}
{!!Form::close()!!}
Syntax gets changing in laravel versions frequently. So always check your version.
Right now i think you might be using Laravel version 5.4.36 or something.
So I think try by changing 'ACTION' to 'URL' as below.
{!!Form::open(['url' => ['PostsController#destroy', $post->id], 'method' => 'POST', 'class' => 'pull-right'])!!}
{{Form::hidden('_method', 'DELETE')}}
{{Form::submit('Delete', ['class' => 'btn btn-danger'])}}
{!!Form::close()!!}
Your action method is fine the way you wrote it. That error literally means that you don't have a controller named PostsController#destroy.
Just run:
php artisan route:list
If the controller exist, the name column would give you the prefix and method Post.destroy and in the same row the action column would give you the controller name PostsController#destroy. Obviously if those two conditions are not there; you get the error:
Action App\Http\Controllers\PostsController#destroy not defined.
You can try to use the action helper function like this action('WelcomeController#log_in') or you can just set the action to a route that provides you the controller.
You've missed a step.
Think back to what the action attribute in an html form looks like:
action="{{ you put a url here, not a controller action }}"
Then consider your routes file, where you should add whatever route you decide to reference within {{ }} above, and map it to your controller action in the routes file.
I'd advise doing this without using Form::, then you will understand it better (and it's no more complicated).
juste you need to change method form inside your form to delete like this :
{!!Form::open(['action' => ['PostsController#destroy', $post->id], 'method' => 'DELETE', 'class' => 'pull-right'])!!}
{{Form::hidden('_method', 'DELETE')}}
{{Form::submit('Delete', ['class' => 'btn btn-danger'])}}
{!!Form::close()!!}
in Laravel 8 full description of the route is required as follows:
{!!Form::open(['action' => ['App\Http\Controllers\PostsController#destroy', $post->id],
'method' => 'POST', 'class' => 'float-right'])!!}
I know this is duplicate problem. Still I'm not able to correct this problem so can anyone help?
Routes.php
Route::post('/form-submit',[
'uses' => 'UserController#formSubmit',
'as' => 'f.submit',
]);
UserController.php
public function formSubmit() #form-submit
{
echo"Form Submit Method";
}
test_view.php
#extends('Layout.master')
#section('Content')
{!! Form::open([
'route' => 'f.submit', 'method' => 'post'
]) !!}
{!! Form::test('username') !!}
{!! Form::submit('submit')!!}
{!! Form::close() !!}
#endsection
If I'm using get method for this code. then directly it is showing Form Submit Method and if I'm using post method then it is showing above error
You need to pass a csrf token along the request within the form.
i think
//change '/form-submit' to 'f.submit'
Route::post('/f.submit',[
'uses' => 'UserController#formSubmit',
'as' => 'f.submit',
])
and add csrf token also
I was getting directly "Form Submit Method" rather than it should open test_view form. I have a solution for it using POST or GET method.
Route::post('/form-submit',['
'uses' => 'UserController#formSubmit'
'as' => 'f.submit'
']});
But POST method still not working.
I use Laravel 5 and have the following routing configuration:
$router->resource('restaurants', 'Registration');
And method:
public function store(Auth $userModel, Request $request){
});
In my view file I specifed form like:
{!! Form::open(array('url' => 'restaurants.store')) !!}
When I submit form I am transfered on the address: restaurants.store and get error:
Sorry, the page you are looking for could not be found.
You can use the url syntax which needs a slash like so:
{!! Form::open(array('url' => 'restaurants/store')) !!}
Or the route syntax (if you've got the route set up) like so:
{!! Form::open(array('route' => 'restaurants.store')) !!}
{!! Form::open(array('url' => route('restaurants.store'))) !!}
change {!! Form::open(array('url' => 'restaurants.store')) !!} with {!! Form::open(array('route' => 'restaurants.store')) !!} and since you use restful, in your routes.php $router->resource('restaurants', 'RestaurantsController');
I have this basic form:
{{ Form::open(array('url' => URL::route('post-account-changeProfilePic'), 'files' => true, ))}}
{{ Form::file('photo') }}
<br />
{{ Form::submit('Regístrarme', array("class" => "button expand round")) }}
{{ Form::close() }}
My Route is inside of 2 groups: before=>Auth and before=>csrf
Route::post('/accont/changeProfilePic', array(
'as' => 'post-account-changeProfilePic',
'uses' => 'CallCenterController#postChangeProfilePic'
));
In my controller, I just dump my variable to see what I got:
public function postChangeProfilePic(){
$input = Input::all();
var_dump($input);
}
These are the errors I am getting:
1- Illuminate \ Session \ TokenMismatchException.
This because of the csrf filter, but since I am using blade, the token is actually there. Also, if I remove the name attribute from the file input, this error will not be displayed.
So far, I decided to place the route outside of the csrf filter until I understand what is going on.
2- After placing the route out of the csrf filter, and try to display all the inputs, I get a null array.
I decided to add a new text field and if I don't select a photo/pic and only send the form like that, it'll dump on screen all the inputs, but of course, the file is empty/null.
Any idea about what I am doing wrong?
In your form try changing this to
array('before' => 'csrf'), function()
{{ Form::open(array('url' => URL::route('post-account-changeProfilePic'), 'before' => 'csrf'), 'files' => true, ))}}
The csrf token should be there by default since you are doing a POST request, so not sure where there is an issue there.
http://laravel.com/docs/4.2/html#csrf-protection
for the input try
public function postChangeProfilePic(){
if (Input::hasFile('photo'))
{
$input= Input::file('photo');
var_dump($input);
}
}
http://laravel.com/docs/4.2/requests#files
Okay I think it could be this
change
{{ Form::open(array('url' => URL::route('post-account-changeProfilePic'),
'files' => true, ))}}
to
{{ Form::open(array('route' => 'post-account-changeProfilePic',
'files' => true )) }}
I don't think you need the ',' at the end of the true either.