mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-01 14:06:15 +00:00
2.x
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Settings;
|
||||
|
||||
use App\Actions\User\CreateUser;
|
||||
use App\Actions\User\UpdateProjects;
|
||||
use App\Actions\User\UpdateUser;
|
||||
use App\Facades\Toast;
|
||||
use App\Helpers\HtmxResponse;
|
||||
@ -48,26 +49,7 @@ public function update(User $user, Request $request): RedirectResponse
|
||||
|
||||
public function updateProjects(User $user, Request $request): HtmxResponse
|
||||
{
|
||||
$this->validate($request, [
|
||||
'projects.*' => [
|
||||
'required',
|
||||
Rule::exists('projects', 'id'),
|
||||
],
|
||||
]);
|
||||
|
||||
$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();
|
||||
}
|
||||
app(UpdateProjects::class)->update($user, $request->input());
|
||||
|
||||
Toast::success('Projects updated successfully');
|
||||
|
||||
|
Reference in New Issue
Block a user