Answers for "laravel view check if data exists"

PHP
1

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,
        ]);
    }
}
Posted by: Guest on November-30-2020

Code answers related to "laravel view check if data exists"

Browse Popular Code Answers by Language