Laravel gibt Daten vom Modell zu einem anderen Controller zurück
Relation : Parent has many Childrens
ParentController:
use App\Models\Children;
public static function showChildrens($parent_id) {
$children = new Children;
$childrens = $children->scopeShow($parent_id);
return compact('childrens');
}
Children Model:
use App\Models\Parent;
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
Worrisome Willet