fix new user bug (#197)

This commit is contained in:
Saeed Vaziry
2024-05-09 00:55:52 +02:00
committed by GitHub
parent 179aefefac
commit 016886f307
9 changed files with 219 additions and 5 deletions

View File

@ -7,6 +7,7 @@
use App\Facades\Toast;
use App\Helpers\HtmxResponse;
use App\Http\Controllers\Controller;
use App\Models\Project;
use App\Models\User;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
@ -56,6 +57,18 @@ public function updateProjects(User $user, Request $request): HtmxResponse
$user->projects()->sync($request->projects);
if ($user->currentProject && ! $user->projects->contains($user->currentProject)) {
$user->current_project_id = null;
$user->save();
}
/** @var Project $firstProject */
$firstProject = $user->projects->first();
if (! $user->currentProject && $firstProject) {
$user->current_project_id = $firstProject->id;
$user->save();
}
Toast::success('Projects updated successfully');
return htmx()->redirect(route('settings.users.show', $user));