0👍
I believe its because you are newing up a Department
before its given a school_id
public function storeLocation(request $request) {
$department = Department::create($request->all());
return $department;
}
Also make sure your Department model has the following
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'school_id',
'department_name',
'department_address',
'department_zip',
'department_city',
'department_phone',
];
The code you have provided also returns a new department even after creating one.
EDIT:
try modifying your post to the following
const location = this.location;
fetch('/api/school/'+this.location.school_id+'/location/store', {
method: 'post',
body: {
...location,
},
header: {
'content-type': 'application/json'
}
})
Source:stackexchange.com