Relation : Parent has many Childrens
ParentController:
use AppModelsChildren;
public static function showChildrens($parent_id) {
$children = new Children;
$childrens = $children->scopeShow($parent_id);
return compact('childrens');
}
Children Model:
use AppModelsParent;
public function parent() {
return $this->belongsTo(Parent::class);
}
public static function scopeShow($parent_id) {
$childrens = Children::where('parent_id', $parent_id)->get();
return $childrens;
}
// Note: Don't use the word "parent" in your app as table it will sometimes create conflicts, this was just for the example
// Like the post if you found it usefull and help other devs to find the good answer