- Complete GGZ Ecademy Laravel backend application - RESTful API for learning products, members, filters - Authentication and authorization system - Database migrations and seeders - Custom CRUD generator commands - Email notification system - Integration with frontend applications
This commit is contained in:
127
app/Console/Commands/CrudGenerator.php
Normal file
127
app/Console/Commands/CrudGenerator.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
class CrudGenerator extends Command
|
||||
{
|
||||
protected $signature = 'crud:generator
|
||||
{name : Class (singular) for example User}';
|
||||
|
||||
protected $description = 'Create CRUD operations';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$name = $this->argument('name');
|
||||
|
||||
$this->controller($name);
|
||||
$this->model($name);
|
||||
$this->service($name);
|
||||
$this->migration($name);
|
||||
// $this->validator($name);
|
||||
//$this->request($name);
|
||||
|
||||
File::append(base_path('routes/api.php'), 'Route::resource(\'' . Str::plural(strtolower($name)) . "', '{$name}Controller');");
|
||||
}
|
||||
|
||||
protected function controller($name)
|
||||
{
|
||||
$controllerTemplate = str_replace(
|
||||
[
|
||||
'{{modelName}}',
|
||||
'{{modelNamePluralLowerCase}}',
|
||||
'{{modelNameSingularLowerCase}}'
|
||||
],
|
||||
[
|
||||
$name,
|
||||
strtolower(Str::plural($name)),
|
||||
strtolower($name)
|
||||
],
|
||||
$this->getStub('Controller')
|
||||
);
|
||||
|
||||
file_put_contents(app_path("/Http/Controllers/{$name}Controller.php"), $controllerTemplate);
|
||||
}
|
||||
|
||||
protected function model($name)
|
||||
{
|
||||
$modelTemplate = str_replace(
|
||||
['{{modelName}}'],
|
||||
[$name],
|
||||
$this->getStub('Model')
|
||||
);
|
||||
|
||||
if (!file_exists($path = app_path('/Repositories')))
|
||||
mkdir($path, 0777, true);
|
||||
|
||||
file_put_contents(app_path("/Repositories/{$name}.php"), $modelTemplate);
|
||||
}
|
||||
|
||||
protected function request($name)
|
||||
{
|
||||
$requestTemplate = str_replace(
|
||||
['{{modelName}}'],
|
||||
[$name],
|
||||
$this->getStub('Request')
|
||||
);
|
||||
|
||||
if (!file_exists($path = app_path('/Http/Requests')))
|
||||
mkdir($path, 0777, true);
|
||||
|
||||
file_put_contents(app_path("/Http/Requests/{$name}Request.php"), $requestTemplate);
|
||||
}
|
||||
|
||||
protected function service($name)
|
||||
{
|
||||
$modelTemplate = str_replace(
|
||||
[
|
||||
'{{modelName}}',
|
||||
'{{modelNameSingularLowerCase}}'
|
||||
],
|
||||
[
|
||||
$name,
|
||||
strtolower($name)
|
||||
],
|
||||
$this->getStub('Service')
|
||||
);
|
||||
|
||||
if (!file_exists($path = app_path('/Services')))
|
||||
mkdir($path, 0777, true);
|
||||
|
||||
file_put_contents(app_path("/Services/{$name}Service.php"), $modelTemplate);
|
||||
}
|
||||
|
||||
protected function migration($name)
|
||||
{
|
||||
$tableName = strtolower(Str::plural($name));
|
||||
Artisan::call('make:migration', ['name' => "create_{$tableName}_table"]);
|
||||
}
|
||||
|
||||
protected function validator($name)
|
||||
{
|
||||
$modelTemplate = str_replace(
|
||||
['{{modelName}}'],
|
||||
[$name],
|
||||
$this->getStub('Validator')
|
||||
);
|
||||
|
||||
if (!file_exists($path = app_path('/Validators')))
|
||||
mkdir($path, 0777, true);
|
||||
|
||||
file_put_contents(app_path("/Validators/{$name}Validator.php"), $modelTemplate);
|
||||
}
|
||||
|
||||
protected function getStub($type)
|
||||
{
|
||||
return file_get_contents(base_path("stubs/custom/$type.stub"));
|
||||
}
|
||||
}
|
||||
84
app/Console/Commands/SendProductEmailNotifications.php
Normal file
84
app/Console/Commands/SendProductEmailNotifications.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\UserService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Mail\CourseNotificationMail;
|
||||
use App\Services\CourseNotificationService;
|
||||
|
||||
class SendProductEmailNotifications extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'send:lp-notifications';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command that checks scheduled learning product notifications, sending emails to users specified.';
|
||||
|
||||
private $userService;
|
||||
|
||||
private $courseNotificationService;
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
UserService $userService,
|
||||
CourseNotificationService $courseNotificationService
|
||||
) {
|
||||
parent::__construct();
|
||||
$this->userService = $userService;
|
||||
$this->courseNotificationService = $courseNotificationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$course_notifications = $this->courseNotificationService->getExpiredToSendWithProducts();
|
||||
|
||||
// No notifications? Exit
|
||||
if ($course_notifications->count() <= 0) return 0;
|
||||
|
||||
foreach ($course_notifications as $notification) {
|
||||
|
||||
$users = json_decode($notification->users);
|
||||
$emails = json_decode($notification->emails);
|
||||
|
||||
// Send emails to not registered users
|
||||
if (count($emails) > 0) {
|
||||
|
||||
foreach ($emails as $email) {
|
||||
Mail::to($email)->queue(new CourseNotificationMail($notification));
|
||||
}
|
||||
}
|
||||
|
||||
// Send emails to specified registered users
|
||||
foreach ($users as $userId) {
|
||||
|
||||
$user = $this->userService->get($userId);
|
||||
Mail::to($user)->queue(new CourseNotificationMail($notification));
|
||||
}
|
||||
|
||||
// Mark as sent
|
||||
$notification->sent = true;
|
||||
$notification->save();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user