Assigning an Alias to a Static Laravel Route


Committed to the LaraBrain by: wjgilmore (@wjgilmore) at October 15, 2015 5:48 pm

Take advantage of view-only routes with the added convenience of referencing a route alias

If you don't plan on passing any dynamic data into a particular view then it probably makes sense to forego creating of a corresponding controller action altogether and just return the view when the associated route is requested. But if you're predisposed to using link generation helpers such as the LaravelCollective/HTML package's HTML::link() method, then you'll also want to create a route alias. This wasn't so obvious to me at first but after doing some digging I found the solution as demonstrated here:

    'as' => 'about.books', 
    function () {
      return view('about.books');

If you're using the HTML::link() helper you can now refer to this alias like so:

{!! HTML::link('about.books', 'Books') !!}