A bit I do not understand how to remove the hasMany relationship. I have a branch table and room. That is, one branch has several rooms. I tried in the documentation to find but so far nothing found, if only foreach to sort through everything and delete records
That's what the error is out
"SQLSTATE[23503]: Foreign key violation: 7 ERROR: UPDATE or DELETE in the table "branch" violates foreign key constraint "room_branch_id_foreign" table "room"
DETAIL: key (id)=(4) still have the links in the table "room". (SQL: delete from "branch" where "id" = 4)"
In the controller
public function destroy($id) { return Branch::destroy($id); }
In the photo above
class Branch extends Model { protected $table = 'branch'; protected $dateFormat = 'U'; protected $fillable = ['name', 'city', 'street', 'build', 'b', 'phone', 'user_id']; public function rooms() { return $this->hasMany('Growth\oom'); } }
There is certainly such an example to do
public function destroy($id) { $branch = Branch::find($id)->rooms(); $branch->delete(); return Branch::destroy($id); }
Or I misunderstand to delete related tables?