initial commit
This commit is contained in:
		
							
								
								
									
										37
									
								
								app/Actions/Jetstream/CreateTeam.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								app/Actions/Jetstream/CreateTeam.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace App\Actions\Jetstream; | ||||
| 
 | ||||
| use Illuminate\Support\Facades\Gate; | ||||
| use Illuminate\Support\Facades\Validator; | ||||
| use Laravel\Jetstream\Contracts\CreatesTeams; | ||||
| use Laravel\Jetstream\Events\AddingTeam; | ||||
| use Laravel\Jetstream\Jetstream; | ||||
| 
 | ||||
| class CreateTeam implements CreatesTeams | ||||
| { | ||||
|     /** | ||||
|      * Validate and create a new team for the given user. | ||||
|      * | ||||
|      * @param  mixed  $user | ||||
|      * @param  array  $input | ||||
|      * @return mixed | ||||
|      */ | ||||
|     public function create($user, array $input) | ||||
|     { | ||||
|         Gate::forUser($user)->authorize('create', Jetstream::newTeamModel()); | ||||
| 
 | ||||
|         Validator::make($input, [ | ||||
|             'name' => ['required', 'string', 'max:255'], | ||||
|         ])->validateWithBag('createTeam'); | ||||
| 
 | ||||
|         AddingTeam::dispatch($user); | ||||
| 
 | ||||
|         $user->switchTeam($team = $user->ownedTeams()->create([ | ||||
|             'name' => $input['name'], | ||||
|             'personal_team' => false, | ||||
|         ])); | ||||
| 
 | ||||
|         return $team; | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user