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.
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');
};
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
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community