Jakiro Dragon
Jakiro Dragon

Reputation: 29

getting laravel local host path error (object not found)

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:

my page inside

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

Answers (1)

Amit Gupta
Amit Gupta

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

Related Questions