Skip to content

Commit

Permalink
updated for laravel 8
Browse files Browse the repository at this point in the history
  • Loading branch information
sarthaksavvy committed Oct 1, 2020
1 parent a246d54 commit 03be767
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 69 deletions.
44 changes: 0 additions & 44 deletions app/Commands/AbcBcd.php

This file was deleted.

6 changes: 5 additions & 1 deletion app/Commands/Crud/CrudMigrationCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class CrudMigrationCreator extends RealMigrationCreator
{
use PackageDetail;

public function __construct()
{
}

/**
* Get the full path to the migration.
*
Expand All @@ -22,7 +26,7 @@ protected function getPath($name, $path)
$path = $this->getComposer()->type === 'library' ? $path . 'src/' : $path;
$path = $path . 'database/migrations';

if (! $this->files->isDirectory($path)) {
if (!$this->files->isDirectory($path)) {
$this->files->makeDirectory($path, 0777, true);
}

Expand Down
14 changes: 8 additions & 6 deletions app/Commands/Crud/MigrateMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Support\Str;
use Illuminate\Support\Composer;
use Illuminate\Database\Console\Migrations\BaseCommand;
use Illuminate\Database\Console\Migrations\TableGuesser;

class MigrateMakeCommand extends BaseCommand
{
Expand All @@ -17,7 +18,8 @@ class MigrateMakeCommand extends BaseCommand
{--create= : The table to be created}
{--table= : The table to migrate}
{--path= : The location where the migration file should be created}
{--realpath : Indicate any provided migration file paths are pre-resolved absolute paths}';
{--realpath : Indicate any provided migration file paths are pre-resolved absolute paths}
{--fullpath : Output the full path of the migration}';

/**
* The console command description.
Expand All @@ -43,7 +45,7 @@ class MigrateMakeCommand extends BaseCommand
/**
* Create a new migration install command instance.
*
* @param \Illuminate\Database\Migrations\MigrationCreator $creator
* @param \App\Commands\Crud\MigrationCreator $creator
* @param \Illuminate\Support\Composer $composer
* @return void
*/
Expand Down Expand Up @@ -74,7 +76,7 @@ public function handle()
// If no table was given as an option but a create option is given then we
// will use the "create" option as the table name. This allows the devs
// to pass a table name into this option as a short-cut for creating.
if (! $table && is_string($create)) {
if (!$table && is_string($create)) {
$table = $create;

$create = true;
Expand All @@ -83,7 +85,7 @@ public function handle()
// Next, we will attempt to guess the table name if this the migration has
// "create" in the name. This will allow us to provide a convenient way
// of creating migrations that create new tables for the application.
if (! $table) {
if (!$table) {
[$table, $create] = TableGuesser::guess($name);
}

Expand Down Expand Up @@ -122,8 +124,8 @@ protected function writeMigration($name, $table, $create)
*/
protected function getMigrationPath()
{
if (! is_null($targetPath = $this->input->getOption('path'))) {
return ! $this->usingRealPath()
if (!is_null($targetPath = $this->input->getOption('path'))) {
return !$this->usingRealPath()
? $this->laravel->basePath() . '/' . $targetPath
: $targetPath;
}
Expand Down
40 changes: 35 additions & 5 deletions app/Commands/Foundation/Factories/FactoryMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace App\Commands\Foundation\Factories;

use Illuminate\Support\Str;
use App\Commands\Helpers\PackageDetail;
use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Input\InputOption;
use App\Commands\Helpers\PackageDetail;
use Illuminate\Support\Str;

class FactoryMakeCommand extends GeneratorCommand
{
Expand Down Expand Up @@ -38,6 +38,9 @@ class FactoryMakeCommand extends GeneratorCommand
*/
protected function getStub()
{
if ($this->option('legacy')) {
return __DIR__ . '/stubs/factory_legacy.stub';
}
return __DIR__ . '/stubs/factory.stub';
}

Expand All @@ -49,13 +52,39 @@ protected function getStub()
*/
protected function buildClass($name)
{
$model = $this->option('model')
$namespaceModel = $this->option('model')
? $this->qualifyClass($this->option('model'))
: 'Model';

if ($this->option('legacy')) {
return str_replace(
'DummyModel',
$namespaceModel,
parent::buildClass($name)
);
}

$model = class_basename($namespaceModel);

if (Str::startsWith($namespaceModel, 'App\\Models')) {
$namespace = Str::beforeLast('Database\\Factories\\' . Str::after($namespaceModel, 'App\\Models\\'), '\\');
} else {
$namespace = 'Database\\Factories';
}

$replace = [
'{{ factoryNamespace }}' => $namespace,
'NamespacedDummyModel' => $namespaceModel,
'{{ namespacedModel }}' => $namespaceModel,
'{{namespacedModel}}' => $namespaceModel,
'DummyModel' => $model,
'{{ model }}' => $model,
'{{model}}' => $model,
];

return str_replace(
'DummyModel',
$model,
array_keys($replace),
array_values($replace),
parent::buildClass($name)
);
}
Expand All @@ -82,6 +111,7 @@ protected function getOptions()
{
return [
['model', 'm', InputOption::VALUE_OPTIONAL, 'The name of the model'],
['legacy', 'l'],
];
}
}
31 changes: 25 additions & 6 deletions app/Commands/Foundation/Factories/stubs/factory.stub
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
<?php

use Faker\Generator as Faker;
namespace {{ factoryNamespace }};

$factory->define(DummyModel::class, function (Faker $faker) {
return [
//
];
});
use Illuminate\Database\Eloquent\Factories\Factory;
use {{ namespacedModel }};

class {{ model }}Factory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = {{ model }}::class;

/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
//
];
}
}
9 changes: 9 additions & 0 deletions app/Commands/Foundation/Factories/stubs/factory_legacy.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

use Faker\Generator as Faker;

$factory->define(DummyModel::class, function (Faker $faker) {
return [
//
];
});
4 changes: 3 additions & 1 deletion app/Commands/Foundation/Migrations/MigrateMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Str;
use Illuminate\Support\Composer;
use Illuminate\Database\Migrations\MigrationCreator;
use Illuminate\Database\Console\Migrations\BaseCommand;

class MigrateMakeCommand extends BaseCommand
Expand All @@ -17,7 +18,8 @@ class MigrateMakeCommand extends BaseCommand
{--create= : The table to be created}
{--table= : The table to migrate}
{--path= : The location where the migration file should be created}
{--realpath : Indicate any provided migration file paths are pre-resolved absolute paths}';
{--realpath : Indicate any provided migration file paths are pre-resolved absolute paths}
{--fullpath : Output the full path of the migration}';

/**
* The console command description.
Expand Down
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
}
],
"require": {
"php": "^7.2",
"illuminate/database": "^6.0",
"laravel-zero/framework": "^6.0",
"padraic/phar-updater": "^1.0.6"
"php": "^7.3",
"illuminate/database": "^8.0",
"laravel-zero/framework": "^8.0"
},
"require-dev": {
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^7.3"
"mockery/mockery": "^1.4.2",
"phpunit/phpunit": "^9.3"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit 03be767

Please sign in to comment.