v2 first commit

This commit is contained in:
denisdulici
2019-11-16 10:21:14 +03:00
parent 5b23e9c2c4
commit 6d50fa8442
3075 changed files with 3451681 additions and 65594 deletions

View File

@ -41,9 +41,11 @@ class BillReminder extends Command
public function handle()
{
// Get all companies
$companies = Company::all();
$companies = Company::enabled()->cursor();
foreach ($companies as $company) {
$this->info('Sending bill reminders for ' . $company->name . ' company.');
// Set company id
session(['company_id' => $company->id]);
@ -51,14 +53,14 @@ class BillReminder extends Command
Overrider::load('settings');
Overrider::load('currencies');
$company->setSettings();
// Don't send reminders if disabled
if (!$company->send_bill_reminder) {
if (!setting('schedule.send_bill_reminder')) {
$this->info('Bill reminders disabled by ' . $company->name . '.');
continue;
}
$days = explode(',', $company->schedule_bill_days);
$days = explode(',', setting('schedule.bill_days'));
foreach ($days as $day) {
$day = (int) trim($day);
@ -69,6 +71,7 @@ class BillReminder extends Command
// Unset company_id
session()->forget('company_id');
setting()->forgetAll();
}
protected function remind($day, $company)
@ -77,7 +80,7 @@ class BillReminder extends Command
$date = Date::today()->addDays($day)->toDateString();
// Get upcoming bills
$bills = Bill::with('vendor')->accrued()->notPaid()->due($date)->get();
$bills = Bill::with('contact')->accrued()->notPaid()->due($date)->cursor();
foreach ($bills as $bill) {
// Notify all users assigned to this company
@ -86,7 +89,7 @@ class BillReminder extends Command
continue;
}
$user->notify(new Notification($bill));
$user->notify(new Notification($bill, 'bill_remind_admin'));
}
}
}

View File

@ -38,10 +38,9 @@ class CompanySeed extends Command
public function handle()
{
$class = $this->laravel->make('CompanySeeder');
$seeder = $class->setContainer($this->laravel)->setCommand($this);
$seeder->__invoke();
}
}

View File

@ -212,7 +212,8 @@ class Install extends Command
}
}
private function createDatabaseTables() {
private function createDatabaseTables()
{
$this->dbHost = $this->option(self::OPT_DB_HOST);
$this->dbPort = $this->option(self::OPT_DB_PORT);
$this->dbName = $this->option(self::OPT_DB_NAME);

View File

@ -41,9 +41,11 @@ class InvoiceReminder extends Command
public function handle()
{
// Get all companies
$companies = Company::all();
$companies = Company::enabled()->cursor();
foreach ($companies as $company) {
$this->info('Sending invoice reminders for ' . $company->name . ' company.');
// Set company id
session(['company_id' => $company->id]);
@ -51,14 +53,14 @@ class InvoiceReminder extends Command
Overrider::load('settings');
Overrider::load('currencies');
$company->setSettings();
// Don't send reminders if disabled
if (!$company->send_invoice_reminder) {
if (!setting('schedule.send_invoice_reminder')) {
$this->info('Invoice reminders disabled by ' . $company->name . '.');
continue;
}
$days = explode(',', $company->schedule_invoice_days);
$days = explode(',', setting('schedule.invoice_days'));
foreach ($days as $day) {
$day = (int) trim($day);
@ -69,6 +71,7 @@ class InvoiceReminder extends Command
// Unset company_id
session()->forget('company_id');
setting()->forgetAll();
}
protected function remind($day, $company)
@ -76,13 +79,13 @@ class InvoiceReminder extends Command
// Get due date
$date = Date::today()->subDays($day)->toDateString();
// Get upcoming bills
$invoices = Invoice::with('customer')->accrued()->notPaid()->due($date)->get();
// Get upcoming invoices
$invoices = Invoice::with('contact')->accrued()->notPaid()->due($date)->cursor();
foreach ($invoices as $invoice) {
// Notify the customer
if ($invoice->customer && !empty($invoice->customer_email)) {
$invoice->customer->notify(new Notification($invoice));
if ($invoice->contact && !empty($invoice->contact_email)) {
$invoice->contact->notify(new Notification($invoice, 'invoice_remind_customer'));
}
// Notify all users assigned to this company
@ -91,7 +94,7 @@ class InvoiceReminder extends Command
continue;
}
$user->notify(new Notification($invoice));
$user->notify(new Notification($invoice, 'invoice_remind_admin'));
}
}
}

View File

@ -1,78 +0,0 @@
<?php
namespace App\Console\Commands;
use App\Models\Module\Module;
use App\Models\Module\ModuleHistory;
use Artisan;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputArgument;
class ModuleDelete extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'module:delete {alias} {company_id}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Delete the specified module.';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$alias = $this->argument('alias');
$company_id = $this->argument('company_id');
$model = Module::alias($alias)->companyId($company_id)->first();
if (!$model) {
$this->info("Module [{$alias}] not found.");
return;
}
$module = $this->laravel['modules']->findByAlias($alias);
$module->delete();
$model->status = 0;
$model->save();
// Add history
$data = [
'company_id' => $company_id,
'module_id' => $model->id,
'category' => $module->get('category'),
'version' => $module->get('version'),
'description' => trans('modules.deleted', ['module' => $module->get('name')]),
];
ModuleHistory::create($data);
Artisan::call('cache:clear');
$this->info("Module [{$alias}] deleted.");
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
array('alias', InputArgument::REQUIRED, 'Module alias.'),
array('company_id', InputArgument::REQUIRED, 'Company ID.'),
);
}
}

View File

@ -1,78 +0,0 @@
<?php
namespace App\Console\Commands;
use App\Models\Module\Module;
use App\Models\Module\ModuleHistory;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputArgument;
class ModuleDisable extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'module:disable {alias} {company_id}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Disable the specified module.';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$alias = $this->argument('alias');
$company_id = $this->argument('company_id');
$model = Module::alias($alias)->companyId($company_id)->first();
if (!$model) {
$this->info("Module [{$alias}] not found.");
return;
}
if ($model->status == 1) {
$model->status = 0;
$model->save();
$module = $this->laravel['modules']->findByAlias($alias);
// Add history
$data = [
'company_id' => $company_id,
'module_id' => $model->id,
'category' => $module->get('category'),
'version' => $module->get('version'),
'description' => trans('modules.disabled', ['module' => $module->get('name')]),
];
ModuleHistory::create($data);
$this->info("Module [{$alias}] disabled.");
} else {
$this->comment("Module [{$alias}] is already disabled.");
}
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
array('alias', InputArgument::REQUIRED, 'Module alias.'),
array('company_id', InputArgument::REQUIRED, 'Company ID.'),
);
}
}

View File

@ -1,78 +0,0 @@
<?php
namespace App\Console\Commands;
use App\Models\Module\Module;
use App\Models\Module\ModuleHistory;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputArgument;
class ModuleEnable extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'module:enable {alias} {company_id}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Enable the specified module.';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$alias = $this->argument('alias');
$company_id = $this->argument('company_id');
$model = Module::alias($alias)->companyId($company_id)->first();
if (!$model) {
$this->info("Module [{$alias}] not found.");
return;
}
if ($model->status == 0) {
$model->status = 1;
$model->save();
$module = $this->laravel['modules']->findByAlias($alias);
// Add history
$data = [
'company_id' => $company_id,
'module_id' => $model->id,
'category' => $module->get('category'),
'version' => $module->get('version'),
'description' => trans('modules.enabled', ['module' => $module->get('name')]),
];
ModuleHistory::create($data);
$this->info("Module [{$alias}] enabled.");
} else {
$this->comment("Module [{$alias}] is already enabled.");
}
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
array('alias', InputArgument::REQUIRED, 'Module alias.'),
array('company_id', InputArgument::REQUIRED, 'Company ID.'),
);
}
}

View File

@ -1,95 +0,0 @@
<?php
namespace App\Console\Commands;
use App\Events\ModuleInstalled;
use App\Models\Module\Module;
use App\Models\Module\ModuleHistory;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputArgument;
class ModuleInstall extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'module:install {alias} {company_id}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Install the specified module.';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$alias = $this->argument('alias');
$company_id = $this->argument('company_id');
$old_company_id = session('company_id');
// Set company id
session(['company_id' => $company_id]);
$request = [
'company_id' => $company_id,
'alias' => strtolower($alias),
'status' => '1',
];
$model = Module::create($request);
$module = $this->laravel['modules']->findByAlias($alias);
// Add history
$data = [
'company_id' => $company_id,
'module_id' => $model->id,
'category' => $module->get('category'),
'version' => $module->get('version'),
'description' => trans('modules.installed', ['module' => $module->get('name')]),
];
ModuleHistory::create($data);
// Clear cache
$this->call('cache:clear');
// Update database
$this->call('migrate', ['--force' => true]);
// Trigger event
event(new ModuleInstalled($alias, $company_id));
// Unset company id
session()->forget('company_id');
// Set company id
if (!empty($old_company_id)) {
session(['company_id' => $old_company_id]);
}
$this->info('Module installed!');
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
array('alias', InputArgument::REQUIRED, 'Module alias.'),
array('company_id', InputArgument::REQUIRED, 'Company ID.'),
);
}
}

View File

@ -2,18 +2,16 @@
namespace App\Console\Commands;
use App\Events\Expense\BillCreated;
use App\Events\Expense\BillRecurring;
use App\Events\Income\InvoiceCreated;
use App\Events\Income\InvoiceRecurring;
use App\Models\Common\Company;
use App\Models\Expense\BillHistory;
use App\Models\Income\InvoiceHistory;
use App\Notifications\Expense\Bill as BillNotification;
use App\Notifications\Income\Invoice as InvoiceNotification;
use App\Traits\Incomes;
use App\Utilities\Overrider;
use Carbon\Carbon;
use Date;
use Illuminate\Console\Command;
use Recurr\Rule;
use Recurr\Transformer\ArrayTransformer;
use Recurr\Transformer\ArrayTransformerConfig;
class RecurringCheck extends Command
{
@ -32,7 +30,14 @@ class RecurringCheck extends Command
* @var string
*/
protected $description = 'Check for recurring';
/**
* The current day.
*
* @var Carbon
*/
protected $today;
/**
* Create a new command instance.
*/
@ -48,12 +53,12 @@ class RecurringCheck extends Command
*/
public function handle()
{
$this->today = Date::today();
// Get all companies
$companies = Company::all();
$companies = Company::enabled()->cursor();
foreach ($companies as $company) {
$this->info('Creating recurring records for ' . $company->name . ' company.');
// Set company id
session(['company_id' => $company->id]);
@ -61,43 +66,11 @@ class RecurringCheck extends Command
Overrider::load('settings');
Overrider::load('currencies');
$company->setSettings();
$this->today = Date::today();
foreach ($company->recurring as $recurring) {
foreach ($recurring->schedule() as $recur) {
$recur_date = Date::parse($recur->getStart()->format('Y-m-d'));
// Check if should recur today
if ($this->today->ne($recur_date)) {
continue;
}
$model = $recurring->recurable;
if (!$model) {
continue;
}
switch ($recurring->recurable_type) {
case 'App\Models\Expense\Bill':
$this->recurBill($company, $model);
break;
case 'App\Models\Income\Invoice':
$this->recurInvoice($company, $model);
break;
case 'App\Models\Expense\Payment':
case 'App\Models\Income\Revenue':
$model->cloneable_relations = [];
// Create new record
$clone = $model->duplicate();
$clone->parent_id = $model->id;
$clone->paid_at = $this->today->format('Y-m-d');
$clone->save();
break;
}
foreach ($recurring->schedule() as $schedule) {
$this->recur($recurring, $schedule);
}
}
}
@ -106,85 +79,90 @@ class RecurringCheck extends Command
session()->forget('company_id');
}
protected function recurInvoice($company, $model)
protected function recur($recurring, $schedule)
{
$model->cloneable_relations = ['items', 'totals'];
$schedule_date = Date::parse($schedule->getStart()->format('Y-m-d'));
// Create new record
$clone = $model->duplicate();
// Set original invoice id
$clone->parent_id = $model->id;
// Days between invoiced and due date
$diff_days = Date::parse($clone->due_at)->diffInDays(Date::parse($clone->invoiced_at));
// Update dates
$clone->invoiced_at = $this->today->format('Y-m-d');
$clone->due_at = $this->today->addDays($diff_days)->format('Y-m-d');
$clone->save();
// Add invoice history
InvoiceHistory::create([
'company_id' => session('company_id'),
'invoice_id' => $clone->id,
'status_code' => 'draft',
'notify' => 0,
'description' => trans('messages.success.added', ['type' => $clone->invoice_number]),
]);
// Notify the customer
if ($clone->customer && !empty($clone->customer_email)) {
$clone->customer->notify(new InvoiceNotification($clone));
// Check if should recur today
if ($this->today->ne($schedule_date)) {
return;
}
// Notify all users assigned to this company
foreach ($company->users as $user) {
if (!$user->can('read-notifications')) {
continue;
}
$user->notify(new InvoiceNotification($clone));
if (!$model = $recurring->recurable) {
return;
}
// Update next invoice number
$this->increaseNextInvoiceNumber();
switch ($recurring->recurable_type) {
case 'App\Models\Expense\Bill':
if (!$clone = $this->getDocumentClone($model, 'billed_at')) {
break;
}
event(new BillCreated($clone));
event(new BillRecurring($clone));
break;
case 'App\Models\Income\Invoice':
if (!$clone = $this->getDocumentClone($model, 'invoiced_at')) {
break;
}
event(new InvoiceCreated($clone));
event(new InvoiceRecurring($clone));
break;
case 'App\Models\Banking\Transaction':
// Skip model created on the same day, but scheduler hasn't run yet
if ($this->today->eq(Date::parse($model->paid_at->format('Y-m-d')))) {
break;
}
$model->cloneable_relations = [];
// Create new record
$clone = $model->duplicate();
$clone->parent_id = $model->id;
$clone->paid_at = $this->today->format('Y-m-d');
$clone->save();
break;
}
}
protected function recurBill($company, $model)
/**
* Clone the document and return it.
*
* @param $model
* @param $date_field
*
* @return boolean|object
*/
protected function getDocumentClone($model, $date_field)
{
// Skip model created on the same day, but scheduler hasn't run yet
if ($this->today->eq(Date::parse($model->$date_field->format('Y-m-d')))) {
return false;
}
$model->cloneable_relations = ['items', 'totals'];
// Create new record
$clone = $model->duplicate();
// Set original bill id
// Set original model id
$clone->parent_id = $model->id;
// Days between invoiced and due date
$diff_days = Date::parse($clone->due_at)->diffInDays(Date::parse($clone->invoiced_at));
// Days between issued and due date
$diff_days = Date::parse($clone->due_at)->diffInDays(Date::parse($clone->$date_field));
// Update dates
$clone->billed_at = $this->today->format('Y-m-d');
$clone->due_at = $this->today->addDays($diff_days)->format('Y-m-d');
$clone->$date_field = $this->today->format('Y-m-d');
$clone->due_at = $this->today->copy()->addDays($diff_days)->format('Y-m-d');
$clone->save();
// Add bill history
BillHistory::create([
'company_id' => session('company_id'),
'bill_id' => $clone->id,
'status_code' => 'draft',
'notify' => 0,
'description' => trans('messages.success.added', ['type' => $clone->bill_number]),
]);
// Notify all users assigned to this company
foreach ($company->users as $user) {
if (!$user->can('read-notifications')) {
continue;
}
$user->notify(new BillNotification($clone));
}
return $clone;
}
}

View File

@ -0,0 +1,46 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class UserSeed extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'user:seed {user} {company}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Seed for specific user';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$class = $this->laravel->make('UserSeeder');
$seeder = $class->setContainer($this->laravel)->setCommand($this);
$seeder->__invoke();
}
}

View File

@ -12,17 +12,7 @@ class Kernel extends ConsoleKernel
*
* @var array
*/
protected $commands = [
Commands\BillReminder::class,
Commands\CompanySeed::class,
Commands\Install::class,
Commands\InvoiceReminder::class,
Commands\ModuleDelete::class,
Commands\ModuleDisable::class,
Commands\ModuleEnable::class,
Commands\ModuleInstall::class,
Commands\RecurringCheck::class,
];
protected $commands = [];
/**
* Define the application's command schedule.
@ -52,5 +42,7 @@ class Kernel extends ConsoleKernel
protected function commands()
{
require base_path('routes/console.php');
$this->load(__DIR__ . '/Commands');
}
}

View File

@ -37,7 +37,7 @@ class $CLASS$ extends Command
*
* @return mixed
*/
public function fire()
public function handle()
{
//
}

View File

@ -11,5 +11,15 @@
"psr-4": {
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\": ""
}
},
"extra": {
"laravel": {
"providers": [
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Providers\\Main"
],
"aliases": {
}
}
}
}

View File

@ -0,0 +1,60 @@
<?php
namespace $CLASS_NAMESPACE$;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
class $CLASS$ extends Controller
{
/**
* Display a listing of the resource.
* @return Response
*/
public function index()
{
//
}
/**
* Store a newly created resource in storage.
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
//
}
/**
* Show the specified resource.
* @param int $id
* @return Response
*/
public function show($id)
{
//
}
/**
* Update the specified resource in storage.
* @param Request $request
* @param int $id
* @return Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
* @param int $id
* @return Response
*/
public function destroy($id)
{
//
}
}

View File

@ -14,7 +14,7 @@ class $CLASS$ extends Controller
*/
public function index()
{
return view('$LOWER_NAME$::index');
return view('$ALIAS$::index');
}
/**
@ -23,50 +23,57 @@ class $CLASS$ extends Controller
*/
public function create()
{
return view('$LOWER_NAME$::create');
return view('$ALIAS$::create');
}
/**
* Store a newly created resource in storage.
* @param Request $request
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
//
}
/**
* Show the specified resource.
* @param int $id
* @return Response
*/
public function show()
public function show($id)
{
return view('$LOWER_NAME$::show');
return view('$ALIAS$::show');
}
/**
* Show the form for editing the specified resource.
* @param int $id
* @return Response
*/
public function edit()
public function edit($id)
{
return view('$LOWER_NAME$::edit');
return view('$ALIAS$::edit');
}
/**
* Update the specified resource in storage.
* @param Request $request
* @param Request $request
* @param int $id
* @return Response
*/
public function update(Request $request)
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
* @param int $id
* @return Response
*/
public function destroy()
public function destroy($id)
{
//
}
}

View File

@ -0,0 +1,9 @@
<?php
use Faker\Generator as Faker;
$factory->define(Model::class, function (Faker $faker) {
return [
//
];
});

View File

@ -0,0 +1,34 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
class $CLASS$ implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//
}
}

View File

@ -2,14 +2,12 @@
namespace $NAMESPACE$;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Bus\Queueable;
use Illuminate\Foundation\Bus\Dispatchable;
class $CLASS$ implements ShouldQueue
{
use InteractsWithQueue, SerializesModels, Queueable;
use Dispatchable, Queueable;
/**
* Create a new job instance.

View File

@ -1,19 +1,14 @@
{
"name": "$STUDLY_NAME$",
"alias": "$LOWER_NAME$",
"description": "",
"alias": "$ALIAS$",
"version": "1.0.0",
"category": "payment-gateway",
"keywords": [],
"category": "accounting",
"active": 1,
"order": 0,
"providers": [
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Providers\\$STUDLY_NAME$ServiceProvider"
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Providers\\Main"
],
"aliases": {},
"files": [
"start.php"
],
"files": [],
"requires": [],
"settings": []
}

View File

@ -0,0 +1,8 @@
<?php
return [
'name' => '$STUDLY_NAME$',
'description' => 'This is my awesome module',
];

View File

@ -0,0 +1,30 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class $CLASS$
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
//
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class $CLASS$ implements ShouldQueue
{
use InteractsWithQueue;
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
//
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace $NAMESPACE$;
use $EVENTNAME$;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class $CLASS$ implements ShouldQueue
{
use InteractsWithQueue;
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param $SHORTEVENTNAME$ $event
* @return void
*/
public function handle($SHORTEVENTNAME$ $event)
{
//
}
}

View File

@ -21,10 +21,10 @@ class $CLASS$
/**
* Handle the event.
*
* @param \$EVENTNAME$ $event
* @param $SHORTEVENTNAME$ $event
* @return void
*/
public function handle(\$EVENTNAME$ $event)
public function handle($SHORTEVENTNAME$ $event)
{
//
}

View File

@ -14,7 +14,7 @@ class $CLASS$ extends Migration
public function up()
{
Schema::create('$TABLE$', function (Blueprint $table) {
$table->increments('id');
$table->bigIncrements('id');
$FIELDS$
$table->timestamps();
});

View File

@ -24,7 +24,7 @@ class $CLASS$ extends Migration
public function down()
{
Schema::create('$TABLE$', function (Blueprint $table) {
$table->increments('id');
$table->bigIncrements('id');
$FIELDS$
$table->timestamps();
});

View File

@ -0,0 +1,17 @@
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"cross-env": "^5.1.4",
"laravel-mix": "^4.0.7",
"laravel-mix-merge-manifest": "^0.1.2"
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Auth\Access\HandlesAuthorization;
class $CLASS$
{
use HandlesAuthorization;
/**
* Create a new policy instance.
*
* @return void
*/
public function __construct()
{
//
}
}

View File

@ -6,13 +6,6 @@ use Illuminate\Support\ServiceProvider;
class $CLASS$ extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* Register the service provider.
*

View File

@ -0,0 +1,19 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Http\Resources\Json\ResourceCollection;
class $CLASS$ extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Http\Resources\Json\Resource;
class $CLASS$ extends Resource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -1,41 +0,0 @@
<?php
namespace $MODULE_NAMESPACE$\$MODULE$\Providers;
use Illuminate\Routing\Router;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class $NAME$ extends ServiceProvider
{
/**
* The root namespace to assume when generating URLs to actions.
*
* @var string
*/
protected $rootUrlNamespace = '$MODULE_NAMESPACE$\$MODULE$\Http\Controllers';
/**
* Called before routes are registered.
*
* Register any model bindings or pattern based filters.
*
* @param Router $router
* @return void
*/
public function before(Router $router)
{
//
}
/**
* Define the routes for the application.
*
* @return void
*/
public function map(Router $router)
{
// if (!app()->routesAreCached()) {
// require __DIR__ . '/Http/routes.php';
// }
}
}

View File

@ -1,6 +0,0 @@
<?php
Route::group(['middleware' => 'web', 'prefix' => '$LOWER_NAME$', 'namespace' => '$MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers'], function()
{
Route::get('/', '$STUDLY_NAME$Controller@index');
});

View File

@ -0,0 +1,10 @@
<?php
Route::group([
'middleware' => 'admin',
'namespace' => 'Modules\$STUDLY_NAME$\Http\Controllers'
], function () {
Route::prefix('$ALIAS$')->group(function() {
// Route::get('/', 'Main@index');
});
});

View File

@ -0,0 +1,10 @@
<?php
Route::group([
'prefix' => 'portal',
'middleware' => 'portal',
'namespace' => 'Modules\$STUDLY_NAME$\Http\Controllers'
], function () {
// Route::get('invoices/{invoice}/$ALIAS$', 'Main@show')->name('portal.invoices.$ALIAS$.show');
// Route::post('invoices/{invoice}/$ALIAS$/confirm', 'Main@confirm')->name('portal.invoices.$ALIAS$.confirm');
});

View File

@ -0,0 +1,40 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Contracts\Validation\Rule;
class $CLASS$ implements Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
//
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'The validation error message.';
}
}

View File

@ -2,18 +2,10 @@
namespace $NAMESPACE$;
use Illuminate\Support\ServiceProvider;
use Illuminate\Database\Eloquent\Factory;
use Illuminate\Support\ServiceProvider as Provider;
class $CLASS$ extends ServiceProvider
class $NAME$ extends Provider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* Boot the application events.
*
@ -21,10 +13,9 @@ class $CLASS$ extends ServiceProvider
*/
public function boot()
{
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
$this->registerFactories();
$this->loadTranslations();
$this->loadViews();
$this->loadMigrations();
}
/**
@ -34,68 +25,57 @@ class $CLASS$ extends ServiceProvider
*/
public function register()
{
//
$this->loadRoutes();
}
/**
* Register config.
* Load views.
*
* @return void
*/
protected function registerConfig()
public function loadViews()
{
$this->publishes([
__DIR__.'/../$PATH_CONFIG$/config.php' => config_path('$LOWER_NAME$.php'),
], 'config');
$this->mergeConfigFrom(
__DIR__.'/../$PATH_CONFIG$/config.php', '$LOWER_NAME$'
);
$this->loadViewsFrom(__DIR__ . '/../Resources/views', '$ALIAS$');
}
/**
* Register views.
* Load translations.
*
* @return void
*/
public function registerViews()
public function loadTranslations()
{
$viewPath = resource_path('views/modules/$LOWER_NAME$');
$sourcePath = __DIR__.'/../$PATH_VIEWS$';
$this->publishes([
$sourcePath => $viewPath
]);
$this->loadViewsFrom(array_merge(array_map(function ($path) {
return $path . '/modules/$LOWER_NAME$';
}, \Config::get('view.paths')), [$sourcePath]), '$LOWER_NAME$');
$this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', '$ALIAS$');
}
/**
* Register translations.
* Load migrations.
*
* @return void
*/
public function registerTranslations()
public function loadMigrations()
{
$langPath = resource_path('lang/modules/$LOWER_NAME$');
$this->loadMigrationsFrom(__DIR__ . '/../$MIGRATIONS_PATH$');
}
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, '$LOWER_NAME$');
} else {
$this->loadTranslationsFrom(__DIR__ .'/../$PATH_LANG$', '$LOWER_NAME$');
/**
* Load routes.
*
* @return void
*/
public function loadRoutes()
{
if (app()->routesAreCached()) {
return;
}
}
/**
* Register an additional directory of factories.
* @source https://github.com/sebastiaanluca/laravel-resource-flow/blob/develop/src/Modules/ModuleServiceProvider.php#L66
*/
public function registerFactories()
{
if (! app()->environment('production')) {
app(Factory::class)->load(__DIR__ . '/Database/factories');
$routes = [
'admin.php',
'portal.php',
];
foreach ($routes as $route) {
$this->loadRoutesFrom(__DIR__ . '/../$ROUTES_PATH$/' . $route);
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace $NAMESPACE$\Database\Seeders;
namespace $NAMESPACE$;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;

View File

@ -1,17 +0,0 @@
<?php
/*
|--------------------------------------------------------------------------
| Register Namespaces And Routes
|--------------------------------------------------------------------------
|
| When a module starting, this file will executed automatically. This helps
| to register some namespaces like translator or view. Also this file
| will load the routes file for each module. You may also modify
| this file as you want.
|
*/
if (!app()->routesAreCached()) {
require __DIR__ . '/Http/routes.php';
}

View File

@ -0,0 +1,19 @@
<?php
namespace $NAMESPACE$;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class $CLASS$ extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testExample()
{
$this->assertTrue(true);
}
}

View File

@ -1,9 +1,9 @@
@extends('$LOWER_NAME$::layouts.master')
@extends('layouts.admin')
@section('content')
<h1>Hello World</h1>
<p>
This view is loaded from module: {!! config('$LOWER_NAME$.name') !!}
This view is loaded from module: {!! config('$ALIAS$.name') !!}
</p>
@stop

View File

@ -1,12 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Module $STUDLY_NAME$</title>
</head>
<body>
@yield('content')
</body>
</html>

View File

@ -0,0 +1,14 @@
const mix = require('laravel-mix');
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
mix.js('Resources/assets/js/$ALIAS$.js', 'Assets/js/');