为了账号安全,请及时绑定邮箱和手机立即绑定

在 null 上调用成员函数 get() - LARAVEL

在 null 上调用成员函数 get() - LARAVEL

PHP
九州编程 2023-04-02 15:04:08
再次寻求您的帮助。只是想知道如果该列为 NULL,是否有任何想法返回一些东西。请看下面的代码: 谢谢!应用控制器 public function index()    {        $user_id = Auth::user()->id;        $applications = application::where('user_id', '=', $user_id)->first()->get();        if (empty($applications)) {            return redirect(route('user.application.index'))->with('message','Application is Succesfully');;        }        else{        return view('user.application.index',compact('applications'));        }    }
查看完整描述

1 回答

?
翻翻过去那场雪

TA贡献2065条经验 获得超13个赞

如果用户未通过身份验证,那么您将收到意外错误。所以首先检查authasAuth::check()


尝试这个 :


use Illuminate\Support\Facades\Auth;


    public function index()

        {

            if(!Auth::check()) {

                   return view('login');

            }


            $applications = Application::where('user_id', $Auth::user()->id)->first();

            if (empty($applications)) {

                return redirect(route('user.application.index'))->with('message','Application is Succesfully');;

            }

            else{

            return view('user.application.index',compact('applications'));

            }

        }


查看完整回答
反对 回复 2023-04-02
  • 1 回答
  • 0 关注
  • 57 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信