Saiful OCG MY
Saiful OCG MY

Reputation: 31

How to add multiple Auth in flm.php for unisharp/laravel-filemanager

i am using laravel 5 4 and "unisharp/laravel-filemanager": "~1.8"

in my project i have multiple Auth like member, client, manager, reseller but only manager and client have access to file upload. here is my flm.php

'middlewares' => ['web', 'auth:client', 'auth:manager'],

this it not working. but 'middlewares' => ['web', 'auth:client'], // working but only client can upload but manager can't upload or 'middlewares' => ['web', 'auth:manager'], // working but only manager can upload but client can't upload

i also tried to use but it not working too 'user_field' => App\Handlers\ConfigHandler::class, and handlers config

if (Auth::guard('client')->check()) {
  return Auth::guard('client')->user()->id;
}
if (Auth::guard('manager')->check()) {
  return Auth::guard('manager')->user()->id;
}

i need middlewares working for both client and manager

thanks

Upvotes: 0

Views: 1451

Answers (1)

Daemon
Daemon

Reputation: 45

Hi I had this same issue in Laravel 5.4 here's how I solved it. first in the laravel-filemanager routes in web.php, i did this.

Route::group(['prefix' => 'laravel-filemanager', 'middleware' => ['web', 'auth:manager,client']], function () {
 \UniSharp\LaravelFilemanager\Lfm::routes();
});

web is the default guard, vendor is a custom guard...in your case it would be auth:manager,client then to avoid users having the same folder names, I needed same folder for all admins(managers) and then the client guard uses auth()->user()->id, i changed laravel-filemanager ConfigHandler to this

<?php
namespace UniSharp\LaravelFilemanager\Handlers;
class ConfigHandler
{
    public function userField()
    {
        if(auth('vendor')->check())
    {      
        return auth()->user()->id;
    }
    else
    {
        return 'admin';
    }
}

   /*public function userField()
     {
    return auth()->user()->id;
     }*/
}

Hope it helps.

Upvotes: 0

Related Questions