laravel的包裹路线中无法访问客户保护?

问题描述

我在项目认值webcustomer中有两个后卫。在项目路径中,当我检查Auth::guard('customer')->check()时,它会向我显示true,但同时在供应商目录中包含的软件包控制器中对其进行检查时,它会向我显示false。结果,它不允许用户访问路线。

奇怪的是,当我一次使用一个防护装置时,它会正常工作。但我不能同时使用两者。 当两个守卫使用不同的路线时,它也可以正常工作 我不知道为什么客户防护没有在包装中得到认证

包裹的路线

<?PHP

Route::group(['namespace' => 'Coldxpress\Ticket\Http\Controllers'],function () {
    Route::group(['middleware' => 'web'],function () {
        
        Route::group(['prefix' => 'tickets','middleware'=>['auth','auth:customer']],function () {
            Route::get('/{filter}','TicketController@index')->name('tickets.index');
            Route::post('/store','TicketController@store')->name('tickets.store');
            Route::post('/update','TicketController@updateTicket')->name('tickets.update');
            Route::get('/filtered_tickets/{filter}','TicketController@filteredTickets')->name('tickets.filtered');
            Route::get('/get_replies/{ticket_id}','TicketController@getReplies')->name('tickets.replies');
            Route::post('/store_reply/{ticket_id}','TicketController@storeReply')->name('tickets.store.reply');
            Route::post('/store_replies_image','TicketController@uploadReplyImage');
        });
        
    });
   
});

包裹的服务提供

<?PHP

namespace Coldxpress\Ticket;

use App\Models\Admin\Customer;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;

class TicketServiceProvider 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 = 'Coldxpress\Ticket\Http\Controllers';

    public function boot()
    {
        dd(\Auth::guard());
        //dd(asset('ticket/assets/plugins/global/plugins.bundle.css'));
        $this->loadRoutesFrom(__DIR__ . '/routes/web.PHP');
        // $this->loadRoutesFrom(__DIR__ . '/routes/api.PHP');
        $this->loadViewsFrom(__DIR__ . '/resources/views','ticket');
        $this->loadMigrationsFrom(__DIR__ . '/database/migrations');
        $this->mapApiRoutes();

        //      $this->publishes([__DIR__.'/resources/ticket' => public_path()],//        'views');

    }

    public function register()
    {
    }


    /**
     * 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(__DIR__ . '/routes/api.PHP');
    }
}

解决方法

也许这将解决: 无需放置多个'auth','auth:'

Route::group(['prefix' => 'tickets','middleware'=>['auth:customer']],function () { ...your route

如果允许多个身份验证防护

Route::group(['prefix' => 'tickets','middleware'=>['auth:customer,2nd_guard,3rd..']],function () { ...your route