From c96af7fd78f6783b4ce53a5e5dcaa08b1d62a39c Mon Sep 17 00:00:00 2001 From: akbarjimi Date: Tue, 2 Mar 2021 16:54:49 +0330 Subject: [PATCH] Nobody had ever created a function like this one before. --- app/Models/Activity.php | 3 +- app/Models/Business.php | 4 +-- app/Models/Comment.php | 2 +- app/Models/Cost.php | 2 +- app/Models/File.php | 2 +- app/Models/Fingerprint.php | 2 +- app/{Utilities => }/Models/Model.php | 2 +- app/Models/Project.php | 4 +-- .../Models/ReportableRelation.php | 0 app/Models/Sprint.php | 5 +--- app/Models/Status.php | 4 +-- app/Models/System.php | 5 +--- app/Models/Tag.php | 4 +-- app/Models/TagTask.php | 2 +- app/Models/Task.php | 18 ++++++------ app/Models/Transaction.php | 4 +-- app/Models/User.php | 4 +-- app/Models/Work.php | 6 ++-- app/Models/Workflow.php | 3 +- app/Utilities/Helpers/enum.php | 28 ++++++++++++++++++- composer.json | 4 +++ database/factories/BusinessFactory.php | 3 +- database/factories/CostFactory.php | 2 +- database/factories/FileFactory.php | 2 +- database/factories/FingerprintFactory.php | 3 +- database/factories/ProjectFactory.php | 5 ++-- database/factories/SprintflowFactory.php | 4 +-- database/factories/SystemFactory.php | 4 +-- database/factories/TagFactory.php | 2 +- database/factories/TaskFactory.php | 2 +- database/factories/TransactionFactory.php | 2 +- database/factories/UserFactory.php | 2 +- database/factories/WorkFactory.php | 3 +- database/factories/WorkflowFactory.php | 4 +-- database/factories/WorkstatusFactory.php | 2 +- database/seeds/BusinessSeeder.php | 12 ++++---- database/seeds/CostSeeder.php | 2 +- database/seeds/DatabaseSeeder.php | 3 -- database/seeds/FileSeeder.php | 13 --------- database/seeds/ProjectSeeder.php | 6 ++-- database/seeds/SprintSeeder.php | 2 +- database/seeds/TagSeeder.php | 7 ++--- database/seeds/TaskSeeder.php | 4 +-- database/seeds/TransactionSeeder.php | 2 +- database/seeds/UserSeeder.php | 6 ++-- database/seeds/WorkSeeder.php | 2 +- database/seeds/WorkflowSeeder.php | 5 ++-- routes/api.php | 10 +++---- 48 files changed, 107 insertions(+), 115 deletions(-) rename app/{Utilities => }/Models/Model.php (99%) rename app/{Utilities => }/Models/ReportableRelation.php (100%) delete mode 100644 database/seeds/FileSeeder.php diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 29e7ef2..805e4a8 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -2,8 +2,7 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; - +use App\Models\Model; class Activity extends Model { diff --git a/app/Models/Business.php b/app/Models/Business.php index 4d6aa0e..671366c 100644 --- a/app/Models/Business.php +++ b/app/Models/Business.php @@ -3,8 +3,8 @@ namespace App\Models; use App\File; -use App\SoftDeletes; -use App\HiLib\Models\Model; +use App\Models\Model; +use App\Models\SoftDeletes; use Illuminate\Validation\Rule; use Illuminate\Http\UploadedFile; use Spatie\MediaLibrary\HasMedia; diff --git a/app/Models/Comment.php b/app/Models/Comment.php index b392b45..ea1c5f8 100644 --- a/app/Models/Comment.php +++ b/app/Models/Comment.php @@ -2,8 +2,8 @@ namespace App\Models; +use App\Models\Model; use Illuminate\Database\Eloquent\Factories\HasFactory; -use Illuminate\Database\Eloquent\Model; class Comment extends Model { diff --git a/app/Models/Cost.php b/app/Models/Cost.php index 8483331..fa06239 100644 --- a/app/Models/Cost.php +++ b/app/Models/Cost.php @@ -2,7 +2,7 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; +use App\Models\Model; class Cost extends Model { diff --git a/app/Models/File.php b/app/Models/File.php index 11f2cd4..2c4c56d 100644 --- a/app/Models/File.php +++ b/app/Models/File.php @@ -2,7 +2,7 @@ namespace App\Models; -use App\HiLib\Models\Model; +use App\Models\Model; use Illuminate\Support\Facades\Storage; class File extends Model diff --git a/app/Models/Fingerprint.php b/app/Models/Fingerprint.php index 34254f2..8db0c86 100644 --- a/app/Models/Fingerprint.php +++ b/app/Models/Fingerprint.php @@ -2,7 +2,7 @@ namespace App\Models; -use App\HiLib\Models\Model; +use App\Models\Model; class Fingerprint extends Model { diff --git a/app/Utilities/Models/Model.php b/app/Models/Model.php similarity index 99% rename from app/Utilities/Models/Model.php rename to app/Models/Model.php index 1dd9b0f..db30979 100644 --- a/app/Utilities/Models/Model.php +++ b/app/Models/Model.php @@ -1,6 +1,6 @@ contains(".") ? "" : "."; // the first parameter of all enum keys are its filename [$filename, $key] = explode(".", $key, 2); // because we do not want to load the file every time use require $enums = require __DIR__ . "/../Enums/$filename.php"; // if the key that user provided not exists then null return $enums = Arr::get($enums, $key, null); // if enum null means that key not found throw_if($enums === null, 'Exception', "Undefined enum '{$key}'"); // if enum value is array its mean that user want to use it as collection return is_array($enums) ? collect($enums) : $enums; } } \ No newline at end of file +contains(".") ? "" : "."; + + // the first parameter of all enum keys are its filename + [$filename, $key] = explode(".", $key, 2); + + // because we do not want to load the file every time use require + $enums = require app_path("Enums/$filename.php"); + + // if the key that user provided not exists then null return + $enums = Arr::get($enums, $key, null); + + // if enum null means that key not found + throw_if($enums === null, 'Exception', "Undefined enum '{$key}'"); + + // if enum value is array its mean that user want to use it as collection + return is_array($enums) ? collect($enums) : $enums; + } +} diff --git a/composer.json b/composer.json index 284899a..566fa2d 100644 --- a/composer.json +++ b/composer.json @@ -56,6 +56,10 @@ }, "files": [ "app/Utilities/Helpers/index.php" + ], + "classmap": [ + "database/seeds", + "database/factories" ] }, "autoload-dev": { diff --git a/database/factories/BusinessFactory.php b/database/factories/BusinessFactory.php index 8a15574..053de00 100644 --- a/database/factories/BusinessFactory.php +++ b/database/factories/BusinessFactory.php @@ -2,10 +2,9 @@ /** @var Factory $factory */ -use App\Business; +use App\Models\Business; use Illuminate\Support\Str; use Faker\Generator as Faker; -use Illuminate\Database\Eloquent\Factory; $factory->define(Business::class, function (Faker $faker) { return [ diff --git a/database/factories/CostFactory.php b/database/factories/CostFactory.php index 649cc16..6e84128 100644 --- a/database/factories/CostFactory.php +++ b/database/factories/CostFactory.php @@ -2,8 +2,8 @@ /** @var Factory $factory */ -use App\Cost; use Carbon\Carbon; +use App\Models\Cost; use Faker\Generator as Faker; $factory->define(Cost::class, function (Faker $faker) { diff --git a/database/factories/FileFactory.php b/database/factories/FileFactory.php index c8a4620..45191da 100644 --- a/database/factories/FileFactory.php +++ b/database/factories/FileFactory.php @@ -2,7 +2,7 @@ /** @var Factory $factory */ -use App\File; +use App\Models\File; use Faker\Generator as Faker; $factory->define(File::class, function (Faker $faker) { diff --git a/database/factories/FingerprintFactory.php b/database/factories/FingerprintFactory.php index bbd8a79..d8458e0 100644 --- a/database/factories/FingerprintFactory.php +++ b/database/factories/FingerprintFactory.php @@ -2,9 +2,8 @@ /** @var Factory $factory */ -use App\Fingerprint; +use App\Models\Fingerprint; use Faker\Factory as Faker; -use Illuminate\Database\Eloquent\Factory; use Illuminate\Support\Arr; use Illuminate\Support\Str; diff --git a/database/factories/ProjectFactory.php b/database/factories/ProjectFactory.php index 6dd5c09..d7dce12 100644 --- a/database/factories/ProjectFactory.php +++ b/database/factories/ProjectFactory.php @@ -2,10 +2,9 @@ /** @var Factory $factory */ -use App\Project; -use Faker\Generator as Faker; -use Illuminate\Database\Eloquent\Factory; +use App\Models\Project; use Illuminate\Support\Str; +use Faker\Generator as Faker; $factory->define(Project::class, function (Faker $faker) { return [ diff --git a/database/factories/SprintflowFactory.php b/database/factories/SprintflowFactory.php index ab520fb..b5c3031 100644 --- a/database/factories/SprintflowFactory.php +++ b/database/factories/SprintflowFactory.php @@ -2,13 +2,13 @@ /** @var \Illuminate\Database\Eloquent\Factory $factory */ -use App\Sprint; +use App\Models\Sprint; use Faker\Generator as Faker; $factory->define(Sprint::class, function (Faker $faker) { return [ 'business_id' => null, - 'name' => $faker->randomElement(['scrum', 'printing', + 'name' => $faker->randomElement(['scrum', 'printing', 'agile', 'develop', 'design', 'writing', 'seo', 'sale']), 'active' => rand(0, 1), 'description' => $faker->paragraph, diff --git a/database/factories/SystemFactory.php b/database/factories/SystemFactory.php index 0ea6223..0631afb 100644 --- a/database/factories/SystemFactory.php +++ b/database/factories/SystemFactory.php @@ -2,10 +2,8 @@ /** @var Factory $factory */ -use App\System; +use App\Models\System; use Faker\Generator as Faker; -use Illuminate\Database\Eloquent\Factory; -use Illuminate\Support\Str; $factory->define(System::class, function (Faker $faker) { return [ diff --git a/database/factories/TagFactory.php b/database/factories/TagFactory.php index d6779b4..5941665 100644 --- a/database/factories/TagFactory.php +++ b/database/factories/TagFactory.php @@ -2,8 +2,8 @@ /** @var \Illuminate\Database\Eloquent\Factory $factory */ -use App\Tag; use Faker\Factory; +use App\Models\Tag; $faker = Factory::create('fa_IR'); $factory->define(Tag::class, function () use ($faker) { diff --git a/database/factories/TaskFactory.php b/database/factories/TaskFactory.php index 713b2cf..66c399a 100644 --- a/database/factories/TaskFactory.php +++ b/database/factories/TaskFactory.php @@ -2,7 +2,7 @@ /** @var \Illuminate\Database\Eloquent\Factory $factory */ -use App\Task; +use App\Models\Task; use Faker\Generator as Faker; $factory->define(Task::class, function (Faker $faker) { diff --git a/database/factories/TransactionFactory.php b/database/factories/TransactionFactory.php index a2f346b..80a58ff 100644 --- a/database/factories/TransactionFactory.php +++ b/database/factories/TransactionFactory.php @@ -3,7 +3,7 @@ /** @var Factory $factory */ use Carbon\Carbon; -use App\Transaction; +use App\Models\Transaction; use Faker\Generator as Faker; use Illuminate\Support\Facades\DB; diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 871ca9d..779f795 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -2,7 +2,7 @@ /** @var \Illuminate\Database\Eloquent\Factory $factory */ -use App\User; +use App\Models\User; use Faker\Generator as Faker; $factory->define(User::class, function (Faker $faker) { diff --git a/database/factories/WorkFactory.php b/database/factories/WorkFactory.php index d4e9e2c..f593e38 100644 --- a/database/factories/WorkFactory.php +++ b/database/factories/WorkFactory.php @@ -2,8 +2,7 @@ /** @var \Illuminate\Database\Eloquent\Factory $factory */ -use App\Work; -use Carbon\Carbon; +use App\Models\Work; use Faker\Generator as Faker; $factory->define(Work::class, function (Faker $faker) { diff --git a/database/factories/WorkflowFactory.php b/database/factories/WorkflowFactory.php index 72cde2f..4d51b1c 100644 --- a/database/factories/WorkflowFactory.php +++ b/database/factories/WorkflowFactory.php @@ -2,13 +2,13 @@ /** @var \Illuminate\Database\Eloquent\Factory $factory */ -use App\Workflow; +use App\Models\Workflow; use Faker\Generator as Faker; $factory->define(Workflow::class, function (Faker $faker) { return [ 'business_id' => null, - 'name' => $faker->randomElement(['scrum', 'printing', + 'name' => $faker->randomElement(['scrum', 'printing', 'agile', 'develop', 'design', 'writing', 'seo', 'sale']), 'desc' => $faker->sentences(1, true), ]; diff --git a/database/factories/WorkstatusFactory.php b/database/factories/WorkstatusFactory.php index 3d2f791..0c5f1fa 100644 --- a/database/factories/WorkstatusFactory.php +++ b/database/factories/WorkstatusFactory.php @@ -2,7 +2,7 @@ /** @var \Illuminate\Database\Eloquent\Factory $factory */ -use App\Status; +use App\Models\Status; use Faker\Generator as Faker; $factory->define(Status::class, function (Faker $faker) { diff --git a/database/seeds/BusinessSeeder.php b/database/seeds/BusinessSeeder.php index f622594..1f39038 100644 --- a/database/seeds/BusinessSeeder.php +++ b/database/seeds/BusinessSeeder.php @@ -1,13 +1,13 @@ raw()); $this->call([ UserSeeder::class, BusinessSeeder::class, @@ -18,7 +16,6 @@ class DatabaseSeeder extends Seeder CostSeeder::class, // ProjectSeeder::class, // TaskSeeder::class, - // FileSeeder::class ]); } } diff --git a/database/seeds/FileSeeder.php b/database/seeds/FileSeeder.php deleted file mode 100644 index e5f927a..0000000 --- a/database/seeds/FileSeeder.php +++ /dev/null @@ -1,13 +0,0 @@ -raw(); - } -} diff --git a/database/seeds/ProjectSeeder.php b/database/seeds/ProjectSeeder.php index 5c91c26..70e0bec 100644 --- a/database/seeds/ProjectSeeder.php +++ b/database/seeds/ProjectSeeder.php @@ -1,9 +1,9 @@ raw([ 'business_id' => $business_id, ]); diff --git a/database/seeds/TaskSeeder.php b/database/seeds/TaskSeeder.php index f138ee0..cc746e6 100755 --- a/database/seeds/TaskSeeder.php +++ b/database/seeds/TaskSeeder.php @@ -1,7 +1,7 @@ group(['prefix' => 'actions'], function () use ($router) { }); }); +$router->get('/callback', 'CreditController@callback'); +$router->get('/{transaction}/redirection', 'CreditController@redirection'); + $router->group(['prefix' => 'auth'], function () use ($router) { $router->get('/', 'AuthController@auth'); $router->delete('/', 'AuthController@delete'); @@ -28,8 +31,6 @@ $router->group(['prefix' => 'auth'], function () use ($router) { $router->get('google/callback', 'AuthController@handleGoogleCallback'); }); - - $router->group(['prefix' => 'businesses'], function () use ($router) { $router->get('/', 'BusinessController@index'); $router->post('/', 'BusinessController@store'); @@ -149,9 +150,6 @@ $router->group(['prefix' => 'businesses'], function () use ($router) { }); }); -$router->get('/callback', 'CreditController@callback'); -$router->get('/{transaction}/redirection', 'CreditController@redirection'); - $router->group(['prefix' => 'users'], function () use ($router) { $router->get('/', 'UserController@index'); $router->get('/search', 'UserController@search'); @@ -163,6 +161,7 @@ $router->group(['prefix' => 'users'], function () use ($router) { $router->delete('/avatar', 'UserController@unSetAvatar'); }); }); + $router->group([], function () use ($router) { $router->post('/log', 'ActivityController@store'); $router->group(['prefix' => 'businesses/{business}', 'middleware' => ['auth', 'bindBusiness']], function ($router) { @@ -182,7 +181,6 @@ $router->group([], function () use ($router) { $router->post('/watchers', 'TaskController@toggleWatcher'); $router->group(['prefix' => 'works'], function ($router) { -// $router->get('/', 'WorkController@index'); $router->post('/', 'WorkController@store'); $router->group(['prefix' => '{work}'], function ($router) { $router->get('/', 'WorkController@show');