Reputation: 29
I'm new to laravel and still learning about this framework. I already found some questions on stackoverflow but it still didn't work out for me.
My problem is:
I got this
localhost/codehub/public/users/create
and the route:
Route::get('users/create',['uses' => 'UserController@create']);
Inside the page there's some form like this:
so when I click create button it is supposed to route it into store function in the user controller
Route::post('users',['uses' => 'UserController@store']);
public function store(Request $request)
{
return $request->all();
}
so the problem is when I click that create button it always redirects me to localhost/users and because of that, I can't process my store function. Any advice?
this is my form code:
<form method="post" action="/users">
<input type="text" name="name">
<input type="email" name="email">
<input type="password" name="password">
<input type="submit" value="Create">
</form>
Upvotes: 1
Views: 742
Reputation: 17668
The problem may be because of relative path in form action.
You should always use named routes which allow the convenient way of generation of URLs or redirects for specific routes. So you can change your route as:
Route::post('users', 'UserController@store')->name('users.create');
And in form you can write as:
<form method="post" action="{{ route('users.create') }}">
Upvotes: 1