If aritcle::find($id) returns null, it should solve the problem:
@if($article = article::find($id) != null)
// If the aricle::find($id) returns anything but null, this block will be reached.
@endif
I think that is better to you to send the data to the view from the controller, instead of using blade directives to fetch data.
something like this:
//Within some controller:
public function show($id)
{
$article = article::find($id);
return view('your-view')->with($article);
}
Then you can check if $article is null using blade:
@if(empty($article))
// The article is empty
@endif
article::find($id)returns null, yes?->get(), it does not make sense there, find() will retrive one model or null.get()onfind()as other users say..but if it returns null you can assign any value to your$articleusing nullcoalesce operator??.$article = article::find($id) ?? []if article db returns null$articlewill be assign to emptyarray()