Zbarcea Christian
Zbarcea Christian

Reputation: 9548

How to use resource routes in Laravel 5?

I have delcared my resource in routes.php:

Route::resource('user', 'UserController');

Now I want to use the link to my html-form:

<form action="{{ URL::route('user') }}" method="post">
    <input type="text" name="username" placeholder="username" /><br />
    <input type="text" name="password" placeholder="password" /><br />
    <input type="text" name="uuid" placeholder="uuid" /><br /><br />
    <input name="_type" type="hidden" value="login" />
    <input type="submit" value="submit" />
</form>

But Laravel is throwing an exception:

production.ERROR: exception 'InvalidArgumentException' with message 'Route [user] not defined.

Upvotes: 0

Views: 364

Answers (2)

Nehal Hasnayeen
Nehal Hasnayeen

Reputation: 1223

Your using wrong route name, use the following

<form action="{{ URL::route('user.store') }}" method="post">

Upvotes: 1

zeratulmdq
zeratulmdq

Reputation: 1494

When you use resources, the name of the route depends on the HTTP method. You can check the names by doing:

php artisan route:list

You have two options. Use the name you get there or just another helper function (which will be easier i think):

URL::action('UserController@store')

Upvotes: 0

Related Questions