I pass an array/object from my database to view file like this:
View::make('home.announcements')
->with('announcements', Announcements::all());
When it is passed to the view file, it contains some integers, like:
$announcements[$k]->month //Output 05
I need to call a function inside base.php
to convert 05 to "May", so I will get "May" result in the view.
<span> {{ $this->convertMonthToString($announcements[$k]->month) }} </span>
//Output: <span>May</span>
I know I can pass it directly with ->with
but that's not what I'm asking. I don't want to pass additional information using additional ->with
's.
I want my views to handle those basic output functions.
How can I do this?
You need to create an function in your 'Announcements' model called:
public function get_fullmonth()
{
return date('F', strtotime($this->get_attribute('month')));
}
Call in in your view as:
@foreach ($announcements as $item)
<span>{{$item->fullmonth}}</span>
@endforeach