From 996b1b4faf94bf22a5d072c4ce00723207a06c26 Mon Sep 17 00:00:00 2001 From: Kamil Niemczycki Date: Tue, 4 Jul 2023 01:25:02 +0200 Subject: [PATCH] - add position --- app/Console/Commands/CreateCV.php | 5 +++- app/Console/Commands/UpdateCV.php | 6 ++++- app/Http/Resources/CVResource.php | 4 ++++ app/Models/CV.php | 1 + ...07_03_231417_add_position_to_cvs_table.php | 24 +++++++++++++++++++ 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 database/migrations/2023_07_03_231417_add_position_to_cvs_table.php diff --git a/app/Console/Commands/CreateCV.php b/app/Console/Commands/CreateCV.php index ed8b26d..1eaf6f8 100644 --- a/app/Console/Commands/CreateCV.php +++ b/app/Console/Commands/CreateCV.php @@ -17,7 +17,8 @@ class CreateCV extends Command {phone : Phone number - with spaces} {location?* : List of locations} {--mission= : Description of mission} - {--rodo= : Description of rodo}'; + {--rodo= : Description of rodo} + {--position= : Set position value}'; protected $description = 'Create CV'; @@ -29,6 +30,7 @@ class CreateCV extends Command $locations = $this->argument('location'); $mission = $this->option('mission'); $rodo = $this->option('rodo'); + $position = $this->option('position'); CV::query() ->create([ @@ -39,6 +41,7 @@ class CreateCV extends Command 'locations' => $locations, 'mission' => $mission, 'rodo' => $rodo, + 'position' => $position, ]); $this->info('Created!'); diff --git a/app/Console/Commands/UpdateCV.php b/app/Console/Commands/UpdateCV.php index 4e51522..cb32e2f 100644 --- a/app/Console/Commands/UpdateCV.php +++ b/app/Console/Commands/UpdateCV.php @@ -17,7 +17,8 @@ class UpdateCV extends Command {--add-location=* : Add locations} {--remove-location=* : Remove lcoations} {--mission= : Set new text value} - {--rodo= : Set new text value}'; + {--rodo= : Set new text value} + {--position= : Set position value}'; protected $description = 'Update CV element'; @@ -66,6 +67,9 @@ class UpdateCV extends Command if ($rodo = $this->option('rodo')) { $cv->rodo = $rodo === 'null' ? null : $rodo; } + if ($position = $this->option('position')) { + $cv->position = $position === 'null' ? null : $position; + } $cv->save(); diff --git a/app/Http/Resources/CVResource.php b/app/Http/Resources/CVResource.php index 7ba2b6e..36d44ef 100644 --- a/app/Http/Resources/CVResource.php +++ b/app/Http/Resources/CVResource.php @@ -27,6 +27,10 @@ class CVResource extends JsonResource !is_null($this->rodo), $this->rodo ), + 'position' => $this->when( + !is_null($this->position), + $this->position + ), ]; } } diff --git a/app/Models/CV.php b/app/Models/CV.php index b1547e7..79941ec 100644 --- a/app/Models/CV.php +++ b/app/Models/CV.php @@ -18,6 +18,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany; * @property array $locations * @property string|null $mission * @property string|null $rodo + * @property string|null $position * @property int $views */ class CV extends Model diff --git a/database/migrations/2023_07_03_231417_add_position_to_cvs_table.php b/database/migrations/2023_07_03_231417_add_position_to_cvs_table.php new file mode 100644 index 0000000..99fb368 --- /dev/null +++ b/database/migrations/2023_07_03_231417_add_position_to_cvs_table.php @@ -0,0 +1,24 @@ +string('position', 255)->nullable(); + }); + } + + public function down(): void + { + Schema::table('cvs', function (Blueprint $table) { + $table->dropColumn('position'); + }); + } +};