Question: Upgraded to Laravel 5.3 - Route Not Defined Error

Question

Upgraded to Laravel 5.3 - Route Not Defined Error

Answers 1
Added at 2016-12-30 22:12
Tags
Question

When previewing the app, I get a route not defined error after the Laravel 5.3 upgrade. It worked in version 5.2.

Route [admin.properties.index] not defined. (View: /home/ubuntu/workspace/resources/views/layouts/app.blade.php) (View: /home/ubuntu/workspace/resources/views/layouts/app.blade.php)

This code is from app.blade.php:

                    <li>{{ link_to_route('admin.properties.index', 'Properties') }}</li>

My web.php file looks like this less the extra routes and comments:

    <?php

Route::get('/', function () {
    return view('welcome');
});

Route::auth();

Route::get('/welcome', 'HomeController@index');

Route::get('/home', 'HomeController@home');

Route::group(
    [
        'prefix' => 'admin',
        'namespace' => 'admin',
        'middleware' => 'admin'
    ],
    function () {

            Route::resource('properties', 'PropertiesController');

    }
);

This is the first part of the Properties Controller for the index view:

    namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Property;
use App\Http\Requests\PropertyRequest;

class PropertiesController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $properties = Property::paginate(15);
        return view('admin.properties.index')->with('properties', $properties);
    }

Am I missing a helper function? Did the syntax change in 5.3 from 5.2 in the above code? Any help from anyone experienced in Laravel 5.3 would be greatly appreciated.

Answers to

Upgraded to Laravel 5.3 - Route Not Defined Error

nr: #1 dodano: 2016-12-30 23:12

The syntax didn't change, however, route naming changed between Laravel 5.2 and Laravel 5.3.

This caused a problem for me problem as well. An issue was raised a while back, but apparently this change is intentional.

Long story short, Laravel 5.3 no longer appends a . after the group prefix when generating the route name.

You can determine the current route name in 5.3 by running php artisan route:list and update your references accordingly.

If you want to emulate the 5.2 route naming, you'll need to tweak the as property for your route group to include the trailing ..

For example:

Route::group([
    'as' => 'admin.',
    'prefix' => 'admin',
    'namespace' => 'admin',
    'middleware' => 'admin'
], // ...
Source Show
◀ Wstecz