eloquent-relationship

Eloquent Count nested relationships

萝らか妹 提交于 2021-02-11 12:20:30
问题 | Data | DataChildren | Category ---------------------------------- | id | id | id | name | data_id | name | | category_id | | | name | Data Model: public function data_children() { return $this->hasMany(DataChildren::class, 'data_id', 'id'); } DataChildren Model: public function category() { return $this->belongsTo(Category::class, 'category_id', 'id'); } I want to get count of Category based on Data id through DataChildren . I just want to take the Category records from Data so the result

Laravel Bulk Detach

ぐ巨炮叔叔 提交于 2021-01-29 04:41:33
问题 First, I use detach() in laravel with this approach and this is work! $student = \App\StudentRegistrars::withTrashed()->findOrFail($id); $student->father_registrars()->detach(); $student->mother_registrars()->detach(); But when I am trying to mass detach in laravel, I can't do that. $students = \App\StudentRegistrars::whereIn('id', $ids); $student->father_registrars()->detach(); $student->mother_registrars()->detach(); Any solution about this problem? 回答1: There's quite a few issues with your