if else view laravel code example
Example 1: laravel if syntax
@if (foo)
@elseif (bar)
@else
@endif
Example 2: laravel if view exists
class CategoryController extends Controller
{
public function show($slug)
{
$category = Category::with('posts')->where('slug', $slug)->firstOrFail();
if (view()->exists('category.custom.'.$category->slug)) {
$view = 'category.custom.'.$category->slug;
} else {
$view = 'category.show';
}
return view($view, [
'category' => $category,
]);
}
}
Example 3: if else statement in laravel blade
@if ($dummy == 1) we have 1 record@elseif ($dummy ==10) we have 10 record@else No record found.@endif