Browse Source

redireccion dependiendo el usuario

main
Damian 22 hours ago
parent
commit
a597e288d1
  1. 10
      app/Http/Controllers/Auth/LoginController.php
  2. 1
      app/Http/Kernel.php
  3. 25
      app/Http/Middleware/CheckMeseroType.php
  4. 11
      resources/views/Mesero/mesero.blade.php
  5. 7
      routes/web.php

10
app/Http/Controllers/Auth/LoginController.php

@ -4,7 +4,7 @@ namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;
class LoginController extends Controller
{
/*
@ -27,6 +27,14 @@ class LoginController extends Controller
*/
protected $redirectTo = '/home';
public function redirectTo(){
if(Auth::user()->puesto_id == 1){
return '/home';
}else{
return '/mesero';
}
}
/**
* Create a new controller instance.
*

1
app/Http/Kernel.php

@ -64,5 +64,6 @@ class Kernel extends HttpKernel
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'adminType' => \App\Http\Middleware\CheckAdminType::class,
'meseroType' => \App\Http\Middleware\CheckMeseroType::class,
];
}

25
app/Http/Middleware/CheckMeseroType.php

@ -0,0 +1,25 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;
class CheckMeseroType
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if(Auth::user()->puesto_id == 2){
return $next($request);
}else{
return back();
}
}
}

11
resources/views/Mesero/mesero.blade.php

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h2>Bienvenido Mesero</h2>
</body>
</html>

7
routes/web.php

@ -36,6 +36,13 @@ Route::resource('trabajadores', TrabajadorController::class);
Route::resource('autos', AutoController::class);
});
Route::middleware(['auth','meseroType'])->group(function(){
Route::get('/mesero/', function(){
return view('Mesero.mesero');
})->name('meseroHome');
});
/*
Route::get('/usuarios', function () {
return view('usuarios');

Loading…
Cancel
Save