Browse Source

Rechazar usuario que no es admin

main
Damian 2 days ago
parent
commit
933fd44c50
  1. 1
      app/Http/Kernel.php
  2. 25
      app/Http/Middleware/CheckAdminType.php
  3. 4
      routes/web.php

1
app/Http/Kernel.php

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

25
app/Http/Middleware/CheckAdminType.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 CheckAdminType
{
/**
* 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 == 1){
return $next($request);
}else{
return back();
}
}
}

4
routes/web.php

@ -21,6 +21,8 @@ Route::get('/', function () {
Auth::routes(['register'=>true,'reset'=>false]); Auth::routes(['register'=>true,'reset'=>false]);
Route::middleware(['auth','adminType'])->group(function(){
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home'); Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::get('/usuarios', [UsuariosController::class,'index'])->name('usuarios'); Route::get('/usuarios', [UsuariosController::class,'index'])->name('usuarios');
@ -32,7 +34,7 @@ Route::post('/usuarios/store', [UsuariosController::class,'store'])->name('usuar
Route::resource('trabajadores', TrabajadorController::class); Route::resource('trabajadores', TrabajadorController::class);
Route::resource('autos', AutoController::class); Route::resource('autos', AutoController::class);
});
/* /*
Route::get('/usuarios', function () { Route::get('/usuarios', function () {

Loading…
Cancel
Save