mercredi 27 juin 2018

Eloquent models comparation troubles

I have some difficulties with eloquent models in use-case like that:

$skill1 = new Skill();
$skill1->title = "Test";
$skill1->save();

$skill3 = Skill::findOrFail($skill1->id);

$this->assertEquals($skill1, $skill3);

Asserting gives error, because objects are not equals Comparasion result here In case we getting object from relation there are lots of new fields (e.g. original->relation)

I know, that there is "is" method in Eloquent models and it works right, but if I need to use core PHP function like in_array (for example, it is using in Collection's "contains" method), comparasion will not work.

The question is "How to compare these two models and use it like that:"

$this->assertTrue(collect([$skill1])->contains($skill3));

Maybe I can overload compare operator, maybe I can make smthng like IComparable in C#?

Thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire