Level 67
https://laravel.com/docs/6.x/eloquent-relationships#inserting-and-updating-related-models
// create a new category
$category = new Category($request->all());
// Save it for the user
auth()->user()->categories()->save($category);
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am getting the following error while trying to insert into the table categories.
CategoryController.php
public function store(CategoryRequest $request)
{
$category = auth()->user()->categories($request->all());
$category->save();
return redirect(route('categories.index'));
}
User.php
public function categories()
{
return $this->hasMany(Category::class);
}
but I get this error.
Too few arguments to function Illuminate\Database\Eloquent\Relations\HasOneOrMany::save(), 0 passed in C:\xampp\htdocs\urmiahardware\blog\app\Http\Controllers\Admin\CategoryController.php on line 43 and exactly 1 expected
https://laravel.com/docs/6.x/eloquent-relationships#inserting-and-updating-related-models
// create a new category
$category = new Category($request->all());
// Save it for the user
auth()->user()->categories()->save($category);
Please or to participate in this conversation.