Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

phpreel/phpreel

126 stars
1 code files
View phpreel/phpreel on GitHub

app/Console/Commands/DevInit.php

Open in GitHub
use Illuminate\Console\Command;
use App\Models\User;
use App\Models\Setting;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Auth\Events\Registered;
 
class DevInit extends Command
{
protected $signature = 'dev:init';
 
protected $description = 'Create phpReel admin account and seed the database (development purposes only)';
 
public function __construct()
{
parent::__construct();
}
 
public function handle()
{
$name = $this->ask('Admin name');
$email = $this->ask('Admin email');
$password = $this->secret('Admin password');
 
try {
$user = User::create([
'name' => $name,
'email' => $email,
'password' => Hash::make($password),
]);
} catch(\Illuminate\Database\QueryException $ex) {
$errorCode = $ex->errorInfo[0];
 
if($errorCode == '23000')
$this->error('Email must be unique, please try a different email (it doesn\'t have to be a real email).');
else
$this->error('Something went wrong, please try again.');
 
return;
}
 
Auth::login($user);
 
event(new Registered($user));
 
$admin = User::where('email', '=', $email)->first();
$admin->roles = 'admin';
$admin->save();
 
$settings = [
['setting' => 'default_subscription', 'value' => 'default']
];
 
Setting::insert($settings);
 
$this->info("Account $email was created successfully.");
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.