Last active
August 6, 2019 07:54
-
-
Save fhulufhelo/609a922d9bef1d1b58028c5dd76784bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\RegisterUser; | |
use App\Mail\WelcomeNewAdmin; | |
use Illuminate\Support\Facades\Mail; | |
use Illuminate\Support\Facades\Auth; | |
use Illuminate\Http\Request; | |
use Illuminate\Auth\Access\AuthorizationException; | |
class RegisterAdmin extends Registering | |
{ | |
public function handle(Request $request) | |
{ | |
$this->guardAgainstUnauthorized(); | |
$user = $this->create($request->all()); | |
// Send welcome email to newly created admin user | |
Mail::to($user)->send(new WelcomeNewAdmin($user)); | |
// rediect user to dashbord | |
return redirect('dashboard.users') | |
->with('status', 'Admin user was successfully added'); | |
} | |
/** | |
* Only SuperAdmin user can add admin user | |
* | |
* @return boolean | |
*/ | |
private function guardAgainstUnauthorized() | |
{ | |
return Auth::check() && Auth::user()->superAdmin() | |
? true | |
: throw new ValidationException( 'This action is unauthorized.' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment