Hi all,
I was wondering how I could do the following. I have a user table with 2 field 'first_name' and 'last_name'.
In my view I want to show the firstname and lastname by using the implode function so I can do something like 'Frederik Jacques, Tim Cook, Barack Obama'
I can now already do this, but it shows only the firstname or last name
{{ $registration->studentGroup->students->implode('first_name', ', ') }}
So I would like to add a property to my User model class which returns the first and lastname
public function getFullName(){
return $this->first_name . ' ' . $this->last_name
}
And then use the implode function like this
{{ $registration->studentGroup->students->implode('fullName', ', ') }}
But this does not work. Any idea's how I can make this work?
Kind regards, Frederik
You can define an accessor in your model.
The doc: http://laravel.com/docs/eloquent#accessors-and-mutators
You can also add your accessor's value to the array and json representation of your model (toArray and toJson) using the $appends model variable.
The doc (see very bottom of page): http://laravel.com/docs/eloquent
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community