这是我的代码:
<?php
use Illuminate\Support\Facades\Session;
namespace App\CustomLibrary
{
class myFunctions {
public function is_login() {
if(Session::get('id') != null){
return TRUE;
}
}
}
}
?>
Run Code Online (Sandbox Code Playgroud)
我是 laravel 5 的新手,我刚刚添加了一个新的自定义函数。在该函数内我想检查会话('id)?但我有这样的错误
myFunctions.php 第 8 行出现 FatalErrorException:未找到类“App\CustomLibrary\Session”
我需要知道如何正确使用会话。
我想做我自己的帮手,然后把它放进去app/http/helpers.php。这是我的助手代码:
<?php
namespace App\Helpers;
use Auth;
class helper {
public static function is_login() {
if(Auth::check()){
return True;
}else{
return False;
}
}
public static function must_login(){
if(Auth::check()){
return True;
}else{
return Redirect::to('logout');;
}
}
}
?>
Run Code Online (Sandbox Code Playgroud)
这是我的app.php代码:
'aliases' => [
'customhelper'=> App\Helpers\Helper::class
]
Run Code Online (Sandbox Code Playgroud)
当我将customhelper::is_login()其刀片文件用于工作时。但是当我尝试在控制器中使用customhelper::must_login()它不起作用时,我遇到了一些错误
找不到类“ App \ Http \ Controllers \ customhelper”