Skip to content

Commit

Permalink
Methods typing and PHPDocs added #35 / Controllers refactoring #36 / …
Browse files Browse the repository at this point in the history
…composer's 'post-install' and 'post-update' scripts removed
  • Loading branch information
anibalealvarezs committed Jan 5, 2022
1 parent 0e165c1 commit 47215a5
Show file tree
Hide file tree
Showing 31 changed files with 639 additions and 466 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,29 @@ composer create-project laravel/laravel my-project
#### 2. Require the package & install it
```shell
composer require anibalealvarezs/projectbuilder-package --no-cache
php artisan pbuilder:install --inertia
php artisan pbuilder:install --all
```
If Jetstream & Inertia already installed, remove the ```--inertia``` flag from the command line
For package updating, you can use these typical options:
```shell
php artisan pbuilder:install
php artisan pbuilder:install --publish --migrate --seed --npm --compile
```
In case of Artisan commands failure, use the alternative installation command:
```
php artisan pbuilder:altinstall
```
For full command information, you can check the help command:
```
php artisan pbuilder:help
```
In case of links failure (if "pbstorage" links show error), navigate to "public folder", manually delete the link, and create a new one with the following command:
```
ln -s ../vendor/anibalealvarezs/projectbuilder-package/src/assets pbstorage
```

***

## Last steps...

#### 3. Add full permissions to Jetstream API by default in ```app/Providers/JetstreamServiceProvider.php``` and remove the default permissions since they will be managed by Spatie's Permissions
```php
protected function configurePermissions()
Expand Down
8 changes: 0 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@
]
}
},
"scripts": {
"post-package-install": [
"php artisan pbuilder:altinstall --all"
],
"post-package-update": [
"php artisan pbuilder:altinstall --publish --migrate --seed --npm --compile"
]
},
"config": {
"sort-packages": true
},
Expand Down
29 changes: 13 additions & 16 deletions src/Commands/PbAltInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ class PbAltInstallCommand extends Command
protected $description = 'Project Builder alternative installation';

/**
* Execute the console command.
* Scope a query to only include popular users.
*
* @return void
* @return bool
*/

public function installInertia()
public function installInertia(): bool
{
try {
echo "---- Requiring Jetstream...\n";
Expand All @@ -64,12 +63,11 @@ public function installInertia()
}

/**
* Execute the console command.
* Scope a query to only include popular users.
*
* @return void
* @return bool
*/

public function publishResources()
public function publishResources(): bool
{
try {
echo "------ Publishing Sanctum's resources...\n";
Expand Down Expand Up @@ -110,12 +108,11 @@ public function publishResources()
}

/**
* Execute the console command.
* Scope a query to only include popular users.
*
* @return void
* @return bool
*/

public function migrateAndSeed()
public function migrateAndSeed(): bool
{
try {
if ($this->option('migrate') || $this->option('all')) {
Expand Down Expand Up @@ -145,12 +142,11 @@ public function migrateAndSeed()
}

/**
* Execute the console command.
* Scope a query to only include popular users.
*
* @return void
* @return bool
*/

public function createLinks()
public function createLinks(): bool
{
echo "------ Adding storage path...\n";
if (!$this->addStoragePath()) {
Expand All @@ -160,5 +156,6 @@ public function createLinks()
if (!shell_exec("php artisan storage:link")) {
echo "------ [[ WARNING: Links could not be created ]]\n";
}
return true;
}
}
4 changes: 2 additions & 2 deletions src/Commands/PbHelpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public function __construct()
public function handle()
{
try {
echo "\n\n";
echo "\n";
echo "[[ Available commands ]]\n\n";
echo ">> pbuilder:install\n";
echo "For package installation\n\n";
echo ">> pbuilder:altinstall\n";
echo "For package installation via 'shell_exec' instead of 'Artisan::call()' method\n\n";
echo "[[ Parameters ]]";
echo "[[ Parameters ]]\n\n";
echo ">> --all | For performing all tasks below\n";
echo ">> --inertia | For installing Jetstream and Inertia\n";
echo ">> --publish | For publishing resources\n";
Expand Down
29 changes: 13 additions & 16 deletions src/Commands/PbInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ class PbInstallCommand extends Command
protected $description = 'Project Builder installation';

/**
* Execute the console command.
* Scope a query to only include popular users.
*
* @return void
* @return bool
*/

public function installInertia()
public function installInertia(): bool
{
try {
echo "---- Requiring Jetstream...\n";
Expand Down Expand Up @@ -72,12 +71,11 @@ public function installInertia()
}

/**
* Execute the console command.
* Scope a query to only include popular users.
*
* @return void
* @return bool
*/

public function publishResources()
public function publishResources(): bool
{
try {
echo "------ Publishing Sanctum's resources...\n";
Expand Down Expand Up @@ -152,12 +150,11 @@ public function publishResources()
}

/**
* Execute the console command.
* Scope a query to only include popular users.
*
* @return void
* @return bool
*/

public function migrateAndSeed()
public function migrateAndSeed(): bool
{
try {
if ($this->option('migrate') || $this->option('all')) {
Expand Down Expand Up @@ -192,12 +189,11 @@ public function migrateAndSeed()
}

/**
* Execute the console command.
* Scope a query to only include popular users.
*
* @return void
* @return bool
*/

public function createLinks()
public function createLinks(): bool
{
echo "------ Adding storage path...\n";
if (!$this->addStoragePath()) {
Expand All @@ -207,5 +203,6 @@ public function createLinks()
if (!Artisan::call('storage:link')) {
echo "------ [[ WARNING: Links could not be created ]]\n";
}
return true;
}
}
10 changes: 6 additions & 4 deletions src/Controllers/Config/PbConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class PbConfigController extends PbBuilderController
function __construct(Request $request, $crud_perms = false)
{
// Vars Override
$this->key = 'Config';
$this->keys = [
'level' => 'Config'
];
// Validation Rules
$this->validationRules = [
'name' => ['required', 'max:190'],
Expand All @@ -47,7 +49,7 @@ public function index(
bool $multiple = false,
string $route = 'level'
): InertiaResponse|JsonResponse|RedirectResponse {
$arrayElements = $this->modelPath::withPublicRelations()->get();
$arrayElements = $this->controllerVars->level->modelPath::withPublicRelations()->get();

return parent::index($arrayElements);
}
Expand All @@ -73,7 +75,7 @@ public function create(string $route = 'level'): InertiaResponse|JsonResponse
*/
public function store(Request $request)
{
$this->validationRules['configkey'] = ['required', 'max:50', Rule::unique($this->table)];
$this->validationRules['configkey'] = ['required', 'max:50', Rule::unique($this->controllerVars->level->table)];

return parent::store($request);
}
Expand Down Expand Up @@ -107,7 +109,7 @@ public function edit(
*/
public function update(Request $request, int $id)
{
$this->validationRules['configkey'] = ['required', 'max:50', Rule::unique($this->table)->ignore($id)];
$this->validationRules['configkey'] = ['required', 'max:50', Rule::unique($this->controllerVars->level->table)->ignore($id)];

return parent::update($request, $id);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Controllers/Logger/PbLoggerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class PbLoggerController extends PbBuilderController
function __construct(Request $request, $crud_perms = false)
{
// Vars Override
$this->key = 'Logger';
$this->keys = [
'level' => 'Logger'
];
// Parent construct
parent::__construct($request, true);
}
Expand All @@ -29,7 +31,7 @@ function __construct(Request $request, $crud_perms = false)
*/
public function index($element = null, bool $multiple = false, string $route = 'level'): InertiaResponse|JsonResponse|RedirectResponse
{
$model = $this->modelPath::withPublicRelations()->get();
$model = $this->controllerVars->level->modelPath::withPublicRelations()->get();

$filtered = $model->map(function ($q) {
return $q->only([
Expand Down
6 changes: 4 additions & 2 deletions src/Controllers/Navigation/PbNavigationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class PbNavigationController extends PbBuilderController
function __construct(Request $request, $crud_perms = false)
{
// Vars Override
$this->key = 'Navigation';
$this->keys = [
'level' => 'Navigation'
];
// Validation Rules
$this->validationRules = [
'name' => ['required', 'max:190'],
Expand Down Expand Up @@ -62,7 +64,7 @@ function __construct(Request $request, $crud_perms = false)
*/
public function index($element = null, bool $multiple = false, string $route = 'level'): InertiaResponse|JsonResponse|RedirectResponse
{
$model = $this->modelPath::withPublicRelations()->orderedByDefault()->get();
$model = $this->controllerVars->level->modelPath::withPublicRelations()->orderedByDefault()->get();

return parent::index($model);
}
Expand Down
Loading

0 comments on commit 47215a5

Please sign in to comment.