From 0145a8073a38bf8cd6a6d91ae7755088685047e3 Mon Sep 17 00:00:00 2001 From: Matt Burchett Date: Fri, 9 Apr 2021 01:35:39 -0700 Subject: [PATCH] Adding Ship Class column --- app/Http/Controllers/ShipsController.php | 8 ++++- app/Models/Ships.php | 2 +- ...1_04_09_081227_add_ship_class_to_ships.php | 32 +++++++++++++++++++ resources/views/ships/index.blade.php | 2 ++ 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 database/migrations/2021_04_09_081227_add_ship_class_to_ships.php diff --git a/app/Http/Controllers/ShipsController.php b/app/Http/Controllers/ShipsController.php index 5b0c2d8..d04337a 100644 --- a/app/Http/Controllers/ShipsController.php +++ b/app/Http/Controllers/ShipsController.php @@ -25,6 +25,8 @@ class ShipsController extends Controller public function add(Request $request){ + $eliteShips = DB::table('elite_ships'); + if($request->input('addShip')) { try { $ship = new Ships; @@ -33,6 +35,8 @@ class ShipsController extends Controller $ship->shipName = request('shipName'); $ship->shipOwner = request('shipOwner'); $ship->shipType = request('shipType'); +// $ship->shipClass = $eliteShips->where('shipName', request('shipType')); + $ship->shipClass = $eliteShips->where('shipName', request('shipType'))->value('shipClass'); $ship->created_at = now(); $ship->save(); }catch(\Exception $e){ @@ -64,7 +68,9 @@ class ShipsController extends Controller 'shipId' => strtoupper(request('shipId')), 'shipName' => request('shipName'), 'shipOwner' => request('shipOwner'), - 'shipType' => request('shipType') + 'shipType' => request('shipType'), +// 'shipClass' => $eliteShips->where('shipName', request('shipType')), + 'shipClass' => $eliteShips->where('shipName', request('shipType'))->value('shipClass'), )); }catch(\Exception $e){ Log::error($e); diff --git a/app/Models/Ships.php b/app/Models/Ships.php index 868bd6f..54d55b2 100644 --- a/app/Models/Ships.php +++ b/app/Models/Ships.php @@ -10,6 +10,6 @@ use Kyslik\ColumnSortable\Sortable; class Ships extends Model { use Sortable; - public $sortable = ['shipId', 'shipName', 'shipOwner', 'shipType']; + public $sortable = ['shipId', 'shipName', 'shipOwner', 'shipType', 'shipClass']; protected $casts = ['id' => 'string']; } diff --git a/database/migrations/2021_04_09_081227_add_ship_class_to_ships.php b/database/migrations/2021_04_09_081227_add_ship_class_to_ships.php new file mode 100644 index 0000000..8d72042 --- /dev/null +++ b/database/migrations/2021_04_09_081227_add_ship_class_to_ships.php @@ -0,0 +1,32 @@ +string('shipClass')->nullable(true); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('ships', function (Blueprint $table) { + $table->dropColumn('shipClass'); + }); + } +} diff --git a/resources/views/ships/index.blade.php b/resources/views/ships/index.blade.php index 58464e1..df0dbd7 100644 --- a/resources/views/ships/index.blade.php +++ b/resources/views/ships/index.blade.php @@ -60,6 +60,7 @@ @sortablelink('shipName', 'Ship Name') @sortablelink('shipType', 'Ship Type') @sortablelink('shipOwner', 'Ship Owner') + @sortablelink('shipClass', 'Ship Class') Actions @@ -70,6 +71,7 @@ {{ $ship->shipName }} {{ $ship->shipType }} {{ $ship->shipOwner }} + {{ $ship->shipClass }}