public function user() {
return $this->hasOne(User::class);
}
public function roles() {
return $this->hasMany(Role::class);
}
When I want to insert data, as far as I understand, I need to do this:
public function insert()
$user = Auth::user();
$user->bios()->store(['description' => 'Test']);
I get the error: "Call to undefined method Illuminate\Database\Eloquent\Relations\HasMany::store()"
I can pull what roles belongs to a user, but I can't insert for some reason. I know I probably oversee a small mistake but it's quite infuriating.
Sorry, I don't know how code formatting works here.
With an Eloquent model, the docs outline how to insert a record:
$flight = new Flight;
$flight->name = $request->name;
$flight->save();
Typically, you will create and insert a record when a user submits a form. You haven't posted much code so it's tough to tell exactly what you're doing. But it looks like you have the insert() function inside of a model. I would recommend following the guidelines from the documentation and handle the insert using a controller.