Reputation: 1229
I need to return a default view if a particular view is not available. I expect something like return view(['order.create', 'base.create'], ['params' => $params]);
Can I achieve this without having set of if statements in Laravel?
Upvotes: 0
Views: 537
Reputation: 1844
Simpler Method
app/config/view.php
paths
, add new view path, for example: 'paths' => [
resource_path('base/views'),
resource_path('views'),
],
view()
function without first()
and array.return view('order.create', compact('params'))
This will load views for base/views
directory first, if not found, then find in the views
directory. Then you can put blade files and directory with same structure.
Upvotes: 1
Reputation: 2683
try this:
return view()->first(['order.create', 'base.create'], ['params' => $params]);
Upvotes: 2