Skip to content

Instantly share code, notes, and snippets.

@4msar
Created October 13, 2023 19:28
Show Gist options
  • Save 4msar/85cde5421c3d4c4ff91225cc03077079 to your computer and use it in GitHub Desktop.
Save 4msar/85cde5421c3d4c4ff91225cc03077079 to your computer and use it in GitHub Desktop.
Simple laravel Artisan command
<?php
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
// inspire with random qoutes
Artisan::command('inspire', function () {
$this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote');
// clear all the log files from storage/logs
Artisan::command('logs:clear', function () {
array_map('unlink', array_filter((array) glob(storage_path('logs/*.log'))));
$this->comment('Logs have been cleared!');
})->describe('Clear log files');
// Interactively reset user password
Artisan::command('user:reset', function () {
// ask for user id or email
$userIdOrEmail = $this->ask('Enter user id or email');
$user = \App\Models\User::where('id', $userIdOrEmail)
->orWhere('email', $userIdOrEmail)
->first();
if (!$user) {
$this->error('User not found!');
return;
}
// ask for new password
$password = $this->secret('Enter new password');
$user->password = bcrypt($password);
$user->save();
$this->comment('Password has been reset!');
})->purpose('Test internal things...');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment