【问题标题】:laravel accessing Session in Modellaravel 访问模型中的 Session
【发布时间】:2021-01-15 19:18:21
【问题描述】:

我正在使用 larave-7。是否可以访问模型中的会话值?

use Illuminate\Database\Eloquent\Model;
use DB;
use Session;
class Permissions extends Model {
function has_permission($menu_controller){
$permission_type = Session::get('permission_type');
    
$result = DB::table('admin_permission')->where('admin_type_id',$permission_type)- >where('apps_menu_id',0)->get();
   

这里我没有从会话中得到任何结果。我怎样才能获得会话值来成功执行我的查询?

【问题讨论】:

    标签: php laravel session model-view-controller model


    【解决方案1】:

    你检查过会话内容吗?

    $data = $request->session()->all();
    

    您是否在会话中输入了权限类型?

    $request->session()->put('key', 'value');
    

    【讨论】:

    • 是的,一切都已使用,但会话不工作
    • 可能缺少中间件 \Illuminate\Session\Middleware\StartSession::class
    • 我有 Illuminate\Session\SessionServiceProvider::class,这个已经添加了。我也应该添加你的吗? @蜗牛
    • 添加到app -> Http -> Kernel.php
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-03
    • 2019-03-09
    • 1970-01-01
    • 1970-01-01
    • 2020-09-14
    • 2023-03-21
    • 1970-01-01
    相关资源
    最近更新 更多