2023-06-16 15:01:58 +02:00
|
|
|
<?php
|
|
|
|
|
2023-12-07 19:06:32 +01:00
|
|
|
namespace App\Livewire\Team;
|
2023-06-16 15:01:58 +02:00
|
|
|
|
|
|
|
use App\Models\Team;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Create extends Component
|
|
|
|
{
|
|
|
|
public string $name = '';
|
|
|
|
public string|null $description = null;
|
|
|
|
|
|
|
|
protected $rules = [
|
|
|
|
'name' => 'required|min:3|max:255',
|
|
|
|
'description' => 'nullable|min:3|max:255',
|
|
|
|
];
|
|
|
|
protected $validationAttributes = [
|
|
|
|
'name' => 'name',
|
|
|
|
'description' => 'description',
|
|
|
|
];
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-06-16 15:01:58 +02:00
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
$this->validate();
|
|
|
|
try {
|
|
|
|
$team = Team::create([
|
|
|
|
'name' => $this->name,
|
|
|
|
'description' => $this->description,
|
|
|
|
'personal_team' => false,
|
|
|
|
]);
|
|
|
|
auth()->user()->teams()->attach($team, ['role' => 'admin']);
|
2023-08-22 17:44:49 +02:00
|
|
|
refreshSession();
|
2023-12-27 16:45:01 +01:00
|
|
|
return redirect()->route('team.index');
|
2023-09-11 17:36:30 +02:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-15 15:34:25 +02:00
|
|
|
return handleError($e, $this);
|
2023-06-16 15:01:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|