vendredi 26 février 2016

How to store classes in Laravel models

I wish to store classes in my Laravel model.

For example, say I have a model called M with an attribute b, which takes a class called Foo.

I wish to be able to to do something like this.

$foo = new Foo();
// ...
$m = new M();
$m->b = $bar;
$m->save();

However this gives me a Object of class Bar could not be converted to string error.

Furthermore I should be able to do the opposite.

e.g.

M::first(5)->b; // Returns the associated `Bar` object who has id 5.

How do I do this?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1R8Q6Ud
via IFTTT

Aucun commentaire:

Enregistrer un commentaire