lasthourcloud/app/Http/Livewire/Team/Create.php

39 lines
960 B
PHP
Raw Normal View History

2023-06-16 13:01:58 +00:00
<?php
namespace App\Http\Livewire\Team;
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-06-16 13:01:58 +00: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 15:44:49 +00:00
refreshSession();
2023-08-30 14:01:38 +00:00
return redirect()->route('team.index');
2023-06-16 13:01:58 +00:00
} catch (\Throwable $th) {
return general_error_handler($th, $this);
}
}
}