Raja Kamran Raja Kamran -3 years ago 126
PHP Question

Laravel 5.2 custom authentication without database or model

Laravel 5.2 custom authentication without database or model while data coming from a remote server that contains true or false

Answer Source

Group the routes with custom auth middleware:

Route::group(['middleware' => 'myauth'], function() {
    Route::get('...');
    Route::post('...');
});

Then create a middleware:

<?php

namespace App\Http\Middleware;

use Closure;

class Myauth
{
    public function handle($request, Closure $next, $guard = null)
    {
        if(session()->has('authenticated')) {
            return $next($request);    
        } else {
            return response('Unauthorized.', 401);
            //OR return redirect()->guest('/');
        }
    }
}

And in some point of your application you need to set the session('authenticated', true)

It's a way to go but your could choose a better approach like OAuth.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download