0
votes

I am currently building a CMS system of which I have created a group of routes for, this group is prefixed with "cms". The problem is within my menu.blade file, where I called the route with the prefix within an hyperlinks HREF attribute and got the following error.

Route [cms/welcome] not defined. (View: C:\Bitnami\wampstack-7.1.27-0\apache2\htdocs\nathanreynolds\resources\views\layouts\CMS\menu.blade.php)

I can visit the route via entering the url in the top of the browser just fine.However when calling the route using {{route('cms/welcome')}} it returns this error.

menu.blade.php

<ul id="CMSnav">
 <li><a href="{{route('cms/welcome')}}">Welcome</a></li>
 <li><a href="{{route('cms/about')}}">About</a></li>
 <li><a href="{{route('cms/contact')}}">Contact us</a></li>
</ul>

web.php (routes)

/** CMS routes **/
Route::group(['prefix'=>'cms','middleware'=>'auth'],function(){
  Route::get('welcome','cmsController@index');
  Route::put('updateLayouts','cmsController@updateLayouts');
  Route::get('about','cmsController@about');
  Route::get('contact','cmsController@contact');
  //Route::resource('/CMS','cmsController');
});

Out print of route list via php artisan route:list

C:\Bitnami\wampstack-7.1.27-0\apache2\htdocs\nathanreynolds>php artisan route:list
+--------+---------------+-------------------------------------------+-----------------------------------+---------------------------------------------------------------------------+------------------+
| Domain | Method        | URI                                       | Name                              | Action                                                                    | Middleware       |
+--------+---------------+-------------------------------------------+-----------------------------------+---------------------------------------------------------------------------+------------------+
|        | GET|HEAD      | /                                         |                                   | Closure                                                                   | web              |
|        | GET|HEAD      | Blogs                                     | Blogs                             | App\Http\Controllers\pagescontroller@Blogs                                | web,Closure      |
|        | GET|HEAD      | CMS/about                                 |                                   | App\Http\Controllers\cmsController@about                                  | web,auth,Closure |
|        | GET|HEAD      | CMS/contact                               |                                   | App\Http\Controllers\cmsController@contact                                | web,auth,Closure |
|        | PUT           | CMS/updateLayouts                         |                                   | App\Http\Controllers\cmsController@updateLayouts                          | web,auth,Closure |
|        | GET|HEAD      | CMS/welcome                               |                                   | App\Http\Controllers\cmsController@index
1

1 Answers

1
votes

The route helper is used to generate a URL for named routes, which is not your case. You have two alternatives to accomplish what you are trying to:

#1 Use url helper instead:

<li><a href="{{url('/cms/welcome')}}">Welcome</a></li>

#2 Use named routes instead. So in your routes file, the routes would be named like:

Route::get('welcome','cmsController@index')->name('cms.welcome');

And then you can use the route helper:

<li><a href="{{route('cms.welcome')}}">Welcome</a></li>