vendredi 28 août 2020

Laravel - Routes & Middleware - Location change from version 5.2 to 5.3

I'm currently upgrading a Laravel application from 5.2 to a current version (7.x). Actually I'm doing the the upgrade from Laravel 5.4 to 5.5. Now I recognized, that in 5.3 the location of routes.php (former app\Http) changed to routes\web.php and routes\api.php. I'm having trouble, to transfer the different routes into the specific files.

I've copied the files of the routes folder into the project and changed the RouteServiceProvider accordingly to the github code from 5.5 (https://github.com/laravel/laravel/blob/5.5/app/Providers/RouteServiceProvider.php):

<?php

namespace App\Providers;

use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;

class RouteServiceProvider extends ServiceProvider
{
    /**
     * This namespace is applied to your controller routes.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'App\Http\Controllers';

    /**
     * The path to the "home" route for your application.
     *
     * @var string
     */
    public const HOME = '/home';

    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @return void
     */
    public function boot()
    {
        //

        parent::boot();
    }

    /**
     * Define the routes for the application.
     *
     * @return void
     */
    public function map()
    {
        $this->mapApiRoutes();

        $this->mapWebRoutes();

        //
    }

    /**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapWebRoutes()
    {
        Route::middleware('web')
            ->namespace($this->namespace)
            ->group(base_path('routes/web.php'));
    }

    /**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapApiRoutes()
    {
        Route::prefix('api')
            ->middleware('api')
            ->namespace($this->namespace)
            ->group(base_path('routes/api.php'));
    }
}

My former routes.php looked like this:

<?php

Route::group(['middleware' => 'web'], function () {
// all web routes without authorization go here:
...

    Route::group(['middleware' => 'auth'], function () {
    // all routes which need authorization go here:
    ...

    });
});

Now I've put all routes without authorization into web.php and all routes which need authorization into the api.php file.

But this configuration does not work. It does not show the pages. The crazy thing is, that also no error logs are produced, so laravel.log is empty.

What is wrong in the RouteServiceProvider or what do I have to change that my routes are working again.

I appriciate any help or hint! Many thanks in advance!



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2G0WgNj
via IFTTT

Aucun commentaire:

Enregistrer un commentaire