Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- class MakeAdmin extends Command
- { /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'make:admin {--name=} {--email=} {--password=} {--remove}';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Make Admin';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $name = ($this->option('name'));
- $email = ($this->option('email'));
- $password = ($this->option('password'));
- if($this->option('remove')){
- try {
- $user = \App\User::where('email',$email)->firstOrFail();
- $user->delete();
- $this->info("user were removed");
- }catch (\Exception $e){
- $this->error('unable to delete user or user doesn\'t exists');
- }
- return;
- }
- try {
- $user = new \App\User();
- $user->name = $name;
- $user->email = $email;
- $user->password = bcrypt($password);
- $user->save();
- $output = "Username : $email , Password : $password";
- $this->info($output);
- }catch (QueryException $e){
- $this->error('It Seems user already exists , try to remove it first with --remove option');
- }
- }
- }
Add Comment
Please, Sign In to add comment