Search code examples
phplaravellaravel-5.3

Route resource not defined laravel 5.3


I'm trying to insert data in laravel 5.3, I'm new to Laravel and I'm trying to use the resource routing system. When I load my page I get -

InvalidArgumentException in UrlGenerator.php line 314:
Route [/admin/register-account.store] not defined.

Routes

Route::group(['middleware' => 'auth'], function() {
   //Applicaion home
   Route::get('/home', 'HomeController@index');

   //Admin routes
   Route::get('/admin/home', 'AdminController@index');

   //Register Account Routes
   Route::resource('/admin/register-account', 'RegAccController');

});

Form

<form action="{{ route('/admin/register-account.store') }}" type="post">
        <input type="text" placeholder="Account name" name="acc_name" />
        <input type="text" placeholder="Account location" name="acc_location" />
        <input type="text" placeholder="Account website" name="acc_website" />

        <input type="hidden" name="_token" value="{{ csrf_token() }}" />
        <button type="submit" class="primary-btn">Register Account</button>
</form>

Controller

public function store(Request $request)
{
  $this->validate($request, [
     'acc_name' => 'required',
     'acc_location' => 'required',
     'acc_website' => 'required',
  ]);

  $regAcc = new Account;
  $regAcc->name = $request->name;
  $regAcc->website = $request->acc_location;
  $regAcc->location = $request->acc_website;
  $regAcc->save();

  return view('admin.reg-acc');
}

I believe my issue is where I define the form action name however I've tried a number of combinations and I can't seem to get another error.


Solution

  • When you're using route() helper, you should use name of the resource route, not path.

    The route() function generates a URL for the given named route

    For example:

    {{ route('register-account.store') }}
    

    You can see actual routes names with executing this command (see Name column):

    php artisan route:list