Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to update with pivot tables? #94

Open
Nemachtilli opened this issue Sep 1, 2022 · 0 comments
Open

how to update with pivot tables? #94

Nemachtilli opened this issue Sep 1, 2022 · 0 comments

Comments

@Nemachtilli
Copy link

Hello this is the following update method:

`public function updateProfile(ProfileRequest $request, Profile $profile) {
try {
\DB::beginTransaction();

        $profile = new Profile;

        $input = [
            $this->profileInput(),
        ];

        $index = 'id';

        /** @var Mavinoo\Batch\Batch $batch */
        $batch = batch();
        $batch->update($profile, $input, $index);
        

        \DB::commit();
        session()->flash("message", ["success", __("<h5>Perfil actualizado</h5>")]);
        return redirect(route('profile', ['profile' => $profile]));
    } catch (\Throwable $exception) {
        \DB::rollBack();
        session()->flash("message", ["danger", $exception->getMessage()]);
        return back();
    }
}`

A new profile create, I have an array of a many to many relationship, for that relationship is saved in the database in the store method, i have:

$profile->hobbies()->sync(request("hobbies"));

putting that line of code in the update method gives me the following error:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'profile_id' cannot be null (SQL: insert into category_profile (category_id, profile_id) values (1, ?))

how can i solve it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant