Support the ongoing development of Laravel.io →
Database Eloquent Forms
Last updated 1 year ago.
0

When the content is stored (new) it has no id. You first have to store the content before storing data into the pivot.
Swap theese lines

            $content->menu()->sync($input);


            Content::create($input);

Reply if it hepled

Last updated 9 years ago.
0

It didn't work. I still got the same error

0

What happens when you try this...

$content = Content::create($input);

dd($content->id);

$content->menu()->sync($input);
0

I got a null

0

T2theC is right. Inside your original code the object stored in the database (result of Content::create) is not assigned to a variable. Sorry, I didn't explore the code enought.
Now we know the problem is that your $content doesn't know it's id after creating.
Is the model successfully saved? Can you find it in the database?
Maybe the guarded is causing problems (probably not). Try remove it for a single test.

0

When I save the data, the data gets saved, but there is no data in the content_menu table which refrences the content and menu tables. I removed the guarded line and and I still got a null.

0

Can someone please help me out.

0

Can someone please help me out.

0

Any Ideas?

0

Any Ideas?

0

Any Ideas?

0

Anything?

0

Hey Quite not sure of my proposal but here it is

Try to replace Content::create($input);

with

$content->fill($attributes)->save(); dd($content->id);

(with replacing $attributes by $input directly or after a manipulation, i didnt took time to compare $input and $attributes type and structure)

Last updated 9 years ago.
0

This is what I get when I replace

Content::create($input);

With

$content->fill($input)->save(); dd($content->id);
int 16
0

I tried to save my stuff without the dd($content-id)

and it kind of worked.

It saved, but there was at least 3 extra rows that was saved in the pivot table.

0

Any idea as to why that happend? And how to fix it?

0

Any ideas?

0

Any ideas?

0

Any ideas?

0

Any ideas?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

shiva shiva Joined 24 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.