How to display content if data is empty in laravel?

Member

by addison , in category: PHP Frameworks , 5 months ago

How to display content if data is empty in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by brandy , 5 months 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."