Support the ongoing development of Laravel.io →
Database Eloquent Laravel
Last updated 1 year ago.
0

I don't think I understand your goal. Can you give a specific example of the issue you're trying to solve?

Eloquent, for the most part, will handle all of the soft delete related updates for you, without any significant effort on your part.

0

Can I define an array of information and use to define the relation functions that Eloquent uses?

Ex: based on that array of information, I want use the following code (or something like that):

Controller

$data = ModelUse::where('id',$id)
    ->with('Relation01')
    ->get();

Model

//USE THIS ARRAY
$relationships = [
    'Relation01' => [
        'type' => 'hasOne',
        'fkey' => 'foreign_key',
        'lkey' => 'local_key',
    ],
    'Relation02' => [
        'type' => 'hasMany',
        'fkey' => 'foreign_key',
        'lkey' => 'local_key',
    ]
];


//INSTEAD OF USING THIS:
public function Relation01(){
    return $this->hasOne('Relation01::class, 'foreign_key', 'local_key');
};
0

Not that I'm aware of. Laravel uses the method version of what you have above for a few things, such as being able to access the relationship easily through the model. Ex) $modelUse->Relation01 (though you should probably use a lower case first letter to stick with Laravel convention).

While you could probably do some black magic using runkit_method_add, it's probably best to stick with the expected method of defining relationships (which have a few more potential options than described above). If any other developers come along later, they'll silently thank you. :D

0

Interesting, I will study more about it. Thank's (:

0

Definitely come back and let us know if you find anything good. :)

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.