why not? Just don't forget to pass model member in view.
But what would i put in my get_url() method? How can I get what model instance it is?
In your Eloquent model add the following variable to the top. This will add a new field to your model.
protected $appends = ['url'];
Continue to add a new accessor method to the same model
public function getUrlAttribute()
{
return URL::to('profile/' . $this->id);
}
This is called an accessor. Read more about what accessors are here: http://laravel.com/docs/eloquent#accessors-and-mutators
You can use it by passing the model data to the view and calling the new field.
<a href="{{ $user->url }}">{{ $user->name }}</a>
I hope this helped you.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community