Reputation: 9
I am working on website where user should enter the category of food along with other infos
There are two tables category and menu, I made one to many relationship:
Now I am trying to store the informatin that I got from user into these tables, and I don't really know how to do that? Below I am trying to that. Could you please help me out with that?
Upvotes: 0
Views: 151
Reputation: 5270
Use like this
$menu = new Menu($menu);
$menu->category()->associate("Your_Category_ID");
$menu->save();
Upvotes: 1
Reputation: 913
If Single Insert a time:
$arr1 = [
'category' => $request->category,
]
$data = Category::create($arr);
if($data) {
$arr2 = [
'title' => $request->title,
'cost' => $request->cost,
'body' => $request->body,
'category_id' => $data->id
]
Menu::create($arra2);
}
And if its multiple insert then create two blank array and push the $arr1 and $arr2 respectively And use insert() to multiple insert
Upvotes: 0