Guest User

Untitled

a guest
Mar 27th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Console\Commands;
  4.  
  5. use Illuminate\Console\Command;
  6.  
  7. class MakeAdmin extends Command
  8. { /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'make:admin {--name=} {--email=} {--password=} {--remove}';
  14.  
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'Make Admin';
  21.  
  22. /**
  23. * Create a new command instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. }
  31.  
  32. /**
  33. * Execute the console command.
  34. *
  35. * @return mixed
  36. */
  37. public function handle()
  38. {
  39. $name = ($this->option('name'));
  40. $email = ($this->option('email'));
  41. $password = ($this->option('password'));
  42. if($this->option('remove')){
  43. try {
  44. $user = \App\User::where('email',$email)->firstOrFail();
  45. $user->delete();
  46. $this->info("user were removed");
  47. }catch (\Exception $e){
  48. $this->error('unable to delete user or user doesn\'t exists');
  49. }
  50. return;
  51. }
  52. try {
  53. $user = new \App\User();
  54. $user->name = $name;
  55. $user->email = $email;
  56. $user->password = bcrypt($password);
  57. $user->save();
  58. $output = "Username : $email , Password : $password";
  59. $this->info($output);
  60. }catch (QueryException $e){
  61. $this->error('It Seems user already exists , try to remove it first with --remove option');
  62. }
  63. }
  64. }
Add Comment
Please, Sign In to add comment