Skip to content

Instantly share code, notes, and snippets.

@fhulufhelo
Last active August 6, 2019 07:54
Show Gist options
  • Save fhulufhelo/609a922d9bef1d1b58028c5dd76784bb to your computer and use it in GitHub Desktop.
Save fhulufhelo/609a922d9bef1d1b58028c5dd76784bb to your computer and use it in GitHub Desktop.
<?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