Advertisement
Guest User

Untitled

a guest
Apr 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. # Laravel Spark disable registration
  2. ```bash
  3. php artisan make:command CreateSuperUser
  4. ```
  5. Open ```app/Console/Commands/CreateSuperUser.php``` and insert
  6. ```php
  7. <?php
  8.  
  9. namespace App\Console\Commands;
  10.  
  11. use Illuminate\Console\Command;
  12. use Laravel\Spark\Spark;
  13.  
  14. class CreateSuperUser extends Command
  15. {
  16. /**
  17. * The name and signature of the console command.
  18. *
  19. * @var string
  20. */
  21. protected $signature = 'super-user:create';
  22.  
  23. /**
  24. * The console command description.
  25. *
  26. * @var string
  27. */
  28. protected $description = 'Create admin user';
  29.  
  30. /**
  31. * Create a new command instance.
  32. *
  33. * @return void
  34. */
  35. public function __construct()
  36. {
  37. parent::__construct();
  38. }
  39.  
  40. /**
  41. * Execute the console command.
  42. *
  43. * @return mixed
  44. */
  45. public function handle()
  46. {
  47. if (env('SUPERUSER_NAME', false) && env('SUPERUSER_EMAIL', false) && env('SUPERUSER_PASSWORD', false)) {
  48. $name = env('SUPERUSER_NAME');
  49. $email = env('SUPERUSER_EMAIL');
  50. $password = env('SUPERUSER_PASSWORD');
  51. } else {
  52. $name = env('SUPERUSER_NAME', $this->ask('Name'));
  53.  
  54. $email = env('SUPERUSER_EMAIL', $this->ask('E-mail'));
  55.  
  56. $password = env('SUPERUSER_PASSWORD', $this->secret('Password'));
  57. $confirm = env('SUPERUSER_PASSWORD', $this->secret('Confirm password'));
  58.  
  59. if ($password !== $confirm) {
  60. $this->error('ERROR: Password and confirmation do not match');
  61.  
  62. return false;
  63. }
  64. }
  65.  
  66. if (strlen($password) < 6) {
  67. $this->error('ERROR: The password at least 6 characters');
  68.  
  69. return false;
  70. }
  71.  
  72. Spark::user()
  73. ->forceFill(
  74. [
  75. 'name' => $name,
  76. 'email' => $email,
  77. 'password' => bcrypt($password),
  78. ]
  79. )
  80. ->save();
  81.  
  82. $this->info('The superuser is created!');
  83. }
  84. }
  85. ```
  86. Open ```app/Console/Kernel.php``` find ````$commands```` array and append our *command* class
  87. ```php
  88. protected $commands = [
  89. Commands\CreateSuperUser::class
  90. ];
  91. ```
  92. ```routes/web.php```
  93. ```php
  94. Route::any('/register', function(){
  95. return redirect()
  96. ->to('/login', 302)
  97. ->with('status', 'Registration disabled.');
  98. });
  99. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement