如何在自定义类laravel 5中使用会话? [英] How to use session in custom class laravel 5?

查看:69
本文介绍了如何在自定义类laravel 5中使用会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

<?php 
use Illuminate\Support\Facades\Session;
namespace App\CustomLibrary

{
    class myFunctions {
        public function is_login() {
            if(Session::get('id') != null){

                return TRUE;
            }
        }
    }
}
?>

我是laravel 5的新用户,我刚刚添加了一个新的自定义函数.在该函数中,我想检查一个会话('id)?但是我有这样的错误

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

myFunctions.php第8行中的

FatalErrorException: 找不到"App \ CustomLibrary \ Session"类

FatalErrorException in myFunctions.php line 8: Class 'App\CustomLibrary\Session' not found

我需要知道如何正确使用会话.

I need to know how to use session properly.

推荐答案

将此子句添加到类顶部,紧接在namespace部分之后:

Add this clause to the top of the class, right after namespace part:

use Session;

或使用完整的名称空间:

Or use full namespace:

if (\Session::get('id') != null)

或使用session()助手:

if (session('id') != null)

这篇关于如何在自定义类laravel 5中使用会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆