dimanche 30 octobre 2016

How to get Larvel5.3 session data or Authentication data from public directory?

I write some php function in public directory because I have use external library then I can't retrieved any session data and authentication data from the controller I have testing with below php script

session_start();
var_dump($_SESSION['user']);

I have initial Session data from AdminMiddlware already It awesome for using it in Resource->view directories but can not in public.

namespace App\Http\Middleware;

use Closure; use App\User; use Illuminate\Support\Facades\Auth;

class AdminMiddleware {

/**
 * Handle an incoming request. User must be logged in to do admin check
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  \Closure  $next
 * @return mixed
 */


public function handle($request, Closure $next)
{

    $user = User::find(\Auth::user()->id);
    if ((int)$user->is_admin == (int)config('auth.guards.is_admin'))
    {

        $collection = collect(Auth::user());
        $thisdata = $collection->toArray();
        $request->session()->put('user', $thisdata);

        return $next($request);
    }

    return redirect()->guest('/');


}

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire