Hello, I'm using Laravel 5.1 at the moment and I had a question. I have a grid that shows values of a certain CRUD and in it I search through Table :: all (), which returns something like:
array:5 [▼
"primary_key_id" => 1,
"foreing_key_id" => 5,
"name" => "testes",
"created_at" => "2015-10-05 21:25:27",
"updated_at" => "2015-10-05 21:25:27"
I would like to add in this object the name of the foreing_key, that is:
array:6 [▼
"primary_key_id" => 1,
"foreing_key_id" => 5,
"name" => "testes",
"created_at" => "2015-10-05 21:25:27",
"updated_at" => "2015-10-05 21:25:27",
**"foreing_key_name = "Teste"**
I tried to use the concept of Mutators of Laravel and through the print I made within the method actually added what I wanted, but I can not access the view and nowhere, and does not appear inside the object inside the controller. Am I using the Mutators concept correctly or am I going to have to do a JOIN to solve this?
Mutator example:
getForeingKeyIdAttribute($value){
$this->attributes['foreing_key_name'] = TableDaForeinkey::where('name','=', $value )->first()->name;
}