 21910f2106
			
		
	
	21910f2106
	
	
	
		
			
			Shift automatically applies the Laravel coding style - which uses the PSR-12 coding style as a base with some minor additions. You may customize the code style applied by configuring [Pint](https://laravel.com/docs/pint), [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer), or [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) for your project root. For more information on customizing the code style applied by Shift, [watch this short video](https://laravelshift.com/videos/shift-code-style).
		
			
				
	
	
		
			55 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Http\Middleware;
 | |
| 
 | |
| use Closure;
 | |
| use Illuminate\Contracts\Auth\Guard;
 | |
| 
 | |
| /**
 | |
|  * Authenticate.
 | |
|  *
 | |
|  * @author    Ladybird <info@ladybirdweb.com>
 | |
|  */
 | |
| class Authenticate
 | |
| {
 | |
|     /**
 | |
|      * The Guard implementation.
 | |
|      *
 | |
|      * @var Guard
 | |
|      */
 | |
|     protected $auth;
 | |
| 
 | |
|     /**
 | |
|      * Create a new filter instance.
 | |
|      *
 | |
|      * @param  Guard  $auth
 | |
|      * @return void
 | |
|      */
 | |
|     public function __construct(Guard $auth)
 | |
|     {
 | |
|         $this->auth = $auth;
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Handle an incoming request.
 | |
|      *
 | |
|      * @param  \Illuminate\Http\Request  $request
 | |
|      * @param  \Closure  $next
 | |
|      * @return mixed
 | |
|      */
 | |
|     public function handle($request, Closure $next)
 | |
|     {
 | |
|         if ($this->auth->guest()) {
 | |
|             if ($request->ajax()) {
 | |
|                 $result = ['fails' => 'Unauthorized! Please login again'];
 | |
| 
 | |
|                 return response()->json(compact('result'));
 | |
|             } else {
 | |
|                 return redirect()->guest('auth/login');
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         return $next($request);
 | |
|     }
 | |
| }
 |