How to display content if data is empty in laravel?

Member

by addison , in category: PHP Frameworks , 10 days ago

How to display content if data is empty in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by brandy , 8 days ago

@addison 

You can use the @empty directive in Laravel Blade to display content if data is empty. Here's an example of how you can use it:

1
2
3
4
5
@if($data->isEmpty())
    <p>No data available.</p>
@else
    <p>Data is available.</p>
@endif


In this example, the isEmpty() method is used to check if the data is empty. If the data is empty, it will display "No data available." Otherwise, it will display "Data is available."