If you are using debugbar then things get even easier. When this package sees that debugbar is registered in the container then it starts collecting data about the view resolution for use in the debugbar. Registered is considered true when the app is on the local environment and debugbar is bound to the app container.
To make it start collecting, just add the collector to the debugbar config (configs/debugbar.php
).
'collectors' => [
...
'auto_views' => true, // Auto resolved view data
...
],
Once this is set up you will see a new tab on the debugbar for “Auto Resolved View”. This will work for both inertia and blade auto resolution. It handles switching the found file between the two syntaxes.
If you are not using Laravel Debugbar then you can use the debug()
method. To use this simply call viewResolution()->debug()
anywhere after you have called $this->view()
in your
controller method. This method returns the view model as is. To make it readable wrap it up in a dd()
.
public function index()
{
// Some logic
$this->view();
dd(viewResolution()->debug());
}
Once called it will print out something like the example below.
ViewModel {#231 ▼
+prefix: null
+controller: "home"
+action: "index"
+view: "home.index"
+prefixes: Collection {#228 ▼
#items: array:3 [▼
0 => "admin"
1 => "home"
2 => "dashboard"
]
}
+attemptedViews: Collection {#227 ▼
#items: array:3 [▼
0 => "admin.home.dashboard.home.index"
1 => "admin.home.index"
2 => "home.index"
]
}
}
If no view was found, $view
will be null. Likewise, if the view was found without a prefix, the prefix will be null.