如何检查Eloquent查询结果中的特定列?

I have free bonus system on my web. In this system. There are 2 tables 1 "deposit " and other is plan. In deposit there is column "plan_id" I want if user has record with plan_d 8 then he should alert message ." You already subscribe free bonus"

I tried following.

$sit = Deposit::where('plan_id', Plan::id)->first();

if ($sit == 8) {
    session()->flash('message', 'Please Add fund at least once to withdraw life time.');
    Session::flash('type', 'warning');
    Session::flash('title', 'warning');
    return redirect()->back();
} 

You're basically checking that a model instance equals 8.

The following will return an instance of Deposit or null;

$sit = Deposit::where('plan_id', Plan::id)->first();

So your if statement should be;

if ($sit && $sit->plan_id == 8) {
    ...
}

You can simply get check if user has deposit with plan id 8 or not for that you need user id. I assuming your deposit table also has user_id, your query will look like this

$sit = Deposit::where('user_id', $user_id)->where('plan_id','8')->first();

if ($sit) {
    session()->flash('message', 'Please Add fund at least once to withdraw life time.');
    Session::flash('type', 'warning');
    Session::flash('title', 'warning');
    return redirect()->back();
}