Replies: 3 comments
-
Hi @zedee |
Beta Was this translation helpful? Give feedback.
-
Hey @tchapi Sorry for the late reply!!! I've been ultra-busy these days and haven't the time to give you a detailed answer. Hopefully it's not useless and can be helpful for you :) I managed to solve it via creating a On your <?php
namespace App\Http\Middleware;
use Closure;
class RedirectToModuleOnRole
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (($request->user()->role === 'YOUR_SPECIFIC_ROLE' || $request->user()->role === 'YOUR_OTHER_SPECIFIC_ROLE') &&
$request->route()->named('admin.projects.index')) {
return redirect(route('admin.secretProjects.index'));
}
elseif (($request->user()->role === 'YOUR_SPECIFIC_ROLE' || $request->user()->role === 'YOUR_OTHER_SPECIFIC_ROLE') &&
$request->route()->named('admin.posts.index')) {
return redirect(route('admin.MagicPosts.index'));
}
return $next($request);
}
} After that, don't forget to include this middleware on your protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \App\Http\Middleware\EnsureEmailIsVerified::class,
'redirect_to_module_on_role' => \App\Http\Middleware\RedirectToModuleOnRole::class //Here goes your custom middleware :)
]; |
Beta Was this translation helpful? Give feedback.
-
By the way, answering to your question:
|
Beta Was this translation helpful? Give feedback.
-
Hi, I've been in a situation like this:
We have two roles:
ADMIN
andGUEST
.We have two modules:
Clients
andProjects
.ADMIN
role can seeClients
andProjects
in the navigation menu.GUEST
role only will seeProjects
.But in
site/config/twill-navigation
file, we have the following:When a user with role
GUEST
logs in, even if it shouldn't seeClients
module, it will be redirected toClients
index, as in the config file there's only oneroute
by default.Is there any way to solve this kind of situations (which in my opinion, is not that exceptional) ?
config
files are out of Laravel'sapp()
scope, so they're not meant to have logic there, actually it shouldn't have any logic at all. Maybe with a custom admin route middleware? Problem is...modules
routes are doing all that magic behind the scenes that I have no idea where to hook this middleware.Beta Was this translation helpful? Give feedback.
All reactions