mehany's avatar
Level 13

Create an attribute that does not exist in the database table?

Is there a way to create an attribute on an Eloquent model that does not exists in its DB table? Say for example, to create composite columns' values with combined attributes!

0 likes
3 replies
mehany's avatar
mehany
OP
Best Answer
Level 13

OMG check this out, i just add in the model:

protected $appends = array('attribute1', 'attribute2');

//then
public function getAttribute1Attribute($attribute1){
    $attribute1 = ...... ;
    return $attribute1;
}

Beautiful :)

3 likes
iosc's avatar

@mehany good question and good answer (^_^)...i have been searching for this solutions to display multiple custom generated tags to be used...thank you!!!

Snapey's avatar

@iosc yes, mutators have been in Laravel for over 8 YEARS

Please or to participate in this conversation.