here is my code:
<?php
use Illuminate\Support\Facades\Session;
namespace App\CustomLibrary
{
class myFunctions {
public function is_login() {
if(Session::get('id') != null){
return TRUE;
}
}
}
}
?>
I'm new in laravel 5, i just added a new custom function. And inside that function i wanna check a session ('id)? But i've got an error like this
FatalErrorException in myFunctions.php line 8: Class 'App\CustomLibrary\Session' not found
I need to know how to use session properly.
use Session; in Model and Controller
// Via a request instance...
$request->session()->put('key', 'value');
// Via the global helper...
session(['key' => 'value']);
for more details https://laravel.com/docs/5.1/session
Add this clause to the top of the class, right after
namespace
part:Or use full namespace:
Or use the
session()
helper:Your
use
needs to be after the namespace declaration:Anything that is
use
d before the namespace is used within the global namespace which changes once a namespace is declared.