laravel if view exists

Solutions on MaxInterview for laravel if view exists by the best coders in the world

showing results for - "laravel if view exists"
Eilidh
31 Nov 2019
1class CategoryController extends Controller
2{
3    public function show($slug)
4    {
5        $category = Category::with('posts')->where('slug', $slug)->firstOrFail();
6
7        if (view()->exists('category.custom.'.$category->slug)) {
8           $view = 'category.custom.'.$category->slug;
9       } else {
10            $view = 'category.show';
11       }
12
13        return view($view, [
14            'category' => $category,
15        ]);
16    }
17}
18