Controller
$userAlbums =album::select('album_id')->where('created_by','=',Auth::id())->count();
$userData = user::where('id','=',Auth::id())->first();
return view('welcome', compact('userData','userAlbums'));
Blade
@if($userData->email_varified_at == null)
@include('include.email-verification')
@endif
if i try to display $userData->email_varified_at variable it works ,but the IF condition also run every time even if email_varified_at field is not null.
is this have any thing to do with casting of filed?
2
Answers
have you tried the empty function?
The empty() function checks whether a variable is empty or not.
This function returns false if the variable exists and is not empty, otherwise it returns true.
The following values evaluate to empty:
0
0.0
"0"
""
NULL
FALSE
array()
The
email_verified_at
field of a User model in Laravel is either a datetime string or null. When you use theif
statement in Blade to check if the field isnull
, you need to useis_null()
or!isset()
instead ofempty()
, which only works with variables that are set but have no value (e.g.,""
,0
,false
,null
,[]
, etc.) but not with variables that are not set at all.Here’s an example of how you can check if the
email_verified_at
field isnull
in your Blade view:This code uses the
is_null()
function to check if theemail_verified_at
field isnull
. Hope this will solve your issue.