Sai Kiran
0
Q:

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,
        ]);
    }
}
0

New to Communities?

Join the community