I am a beginner in laravel and developing an application in Laravel 5.3
. I created one common_helper.php
file in app/Helpers
directory and created a service provider
and added it in config/app.php
.
I tried to call a function located in the common helper
from my controller. It is going to the helper file. But Not showing the session value in the common helper, which is available in the controller.
I already did something in laravel 5.2. But there the same structure working perfectly
What may be the issue? I couldn't figure out it. Please help
common_helper.php
<?php
use App\User;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Route;
use App\Http\Requests;
use App\Menu_master;
use Illuminate\Support\Facades\Input;
use Intervention\Image\Facades\Image as Image;
function check_session()
{
echo Session::get('email');die;
if (Session::has('email') && Session::has('login') && Session::has('role_id') && Session::has('role_name'))
{
if (empty(Session::get('email')) || Session::get('login') !== 'true' || empty(Session::get('role_id')) || empty(Session::get('role_name')))
{
Session::flush();
Redirect::to('/')->send();
exit(0);
}
}
else
{
Session::flush();
Redirect::to('/')->send();
exit(0);
}
}
I am calling the check_session()
from the controller construct
function like below
public function __construct(){
check_session();
}
You should use the session's namespace first.
use Session;
//or
use Illuminate\Support\Facades\Session;