Support the ongoing development of Laravel.io →
posted 4 years ago

Hi,

i store an relation in the user model, but as soon as i save the authenticated user, a new login always response "Unauthenticated". This is the store method:

$this->authorize('create', Organization::class);
$organization = Organization::create($request->validated());
Auth::user()->organization()->associate($organization)->save();

This are the relation to the organization in the user-model:

public function organization(): BelongsTo
{
    return $this->belongsTo(Organization::class, 'organization_id');
}

and the relation in the organization-model to the user:

public function users(): HasMany
{
     return $this->hasMany(User::class);
}

Things like:

User::find(Auth::user()->getAuthIdentifier())->first()->update(['organization_id' => $organization->id]);
Auth::user()->forceFill(['organization' => $organization->id])->save()

brings the same effect.

I dump after save() the user with dd(Auth::user()) and i see in the changes array, that the password is in it. Maybe this is the problem, but i don't know, the hash is the same in the database before and after save.

Anybody an idea?

Cheers Ralf

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Ralf ralf Joined 26 Jan 2017

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.

© 2025 Laravel.io - All rights reserved.