Is there a way to use model's static functions in view? What I am trying to do is fetch booth name while I have the booth ID in the view.
{{booth::find($voter->boothId)->name}}
Join Stack Overflow to learn, share knowledge, and build your career.
Yes you can, but class name must be full name for example App\booth
{{App\booth::find($voter->boothId)->name}}
Or you can add class alias in app.config
'aliases' => [
....
'booth' => App\boot::class \\ your class namespace
],
and in .blade use
{{booth::find($voter->boothId)->name}}
But for good practice you must be check booth::find($voter->boothId)
null or instance of boot
model
For example
@php($booth = booth::find($voter->boothId))
{{$booth ? $booth->name : 'some content'}}
booth
class? – Adre Astrian Jul 5 '18 at 12:53