jeudi 3 septembre 2020

customer guard is not accessible in package's routes in laravel?

I have two guards in project default web and customer .both works fine. in project route when I check Auth::guard('customer')->check() it shows me true but at the same time when check it in my package's controller which is present inside vendor directory it shows me false . In the result it doesn't allow user to visit the route.

Strange thing is that when i use one guard at a time it work fines. but i cant use both at a same time. it also work fine when use different route for both guards I dont know why customer guard is not authenticated in package

package's routes

<?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');
        });
        
    });
   
});

Package's Service Provide

<?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');
    }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire