Adding Ship Class column

This commit is contained in:
Matt Burchett 2021-04-09 01:35:39 -07:00
parent 589bf47eff
commit 0145a8073a
4 changed files with 42 additions and 2 deletions

View File

@ -25,6 +25,8 @@ class ShipsController extends Controller
public function add(Request $request){ public function add(Request $request){
$eliteShips = DB::table('elite_ships');
if($request->input('addShip')) { if($request->input('addShip')) {
try { try {
$ship = new Ships; $ship = new Ships;
@ -33,6 +35,8 @@ class ShipsController extends Controller
$ship->shipName = request('shipName'); $ship->shipName = request('shipName');
$ship->shipOwner = request('shipOwner'); $ship->shipOwner = request('shipOwner');
$ship->shipType = request('shipType'); $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->created_at = now();
$ship->save(); $ship->save();
}catch(\Exception $e){ }catch(\Exception $e){
@ -64,7 +68,9 @@ class ShipsController extends Controller
'shipId' => strtoupper(request('shipId')), 'shipId' => strtoupper(request('shipId')),
'shipName' => request('shipName'), 'shipName' => request('shipName'),
'shipOwner' => request('shipOwner'), '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){ }catch(\Exception $e){
Log::error($e); Log::error($e);

View File

@ -10,6 +10,6 @@ use Kyslik\ColumnSortable\Sortable;
class Ships extends Model class Ships extends Model
{ {
use Sortable; use Sortable;
public $sortable = ['shipId', 'shipName', 'shipOwner', 'shipType']; public $sortable = ['shipId', 'shipName', 'shipOwner', 'shipType', 'shipClass'];
protected $casts = ['id' => 'string']; protected $casts = ['id' => 'string'];
} }

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddShipClassToShips extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('ships', function (Blueprint $table) {
$table->string('shipClass')->nullable(true);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('ships', function (Blueprint $table) {
$table->dropColumn('shipClass');
});
}
}

View File

@ -60,6 +60,7 @@
<th scope="col">@sortablelink('shipName', 'Ship Name')</th> <th scope="col">@sortablelink('shipName', 'Ship Name')</th>
<th scope="col">@sortablelink('shipType', 'Ship Type')</th> <th scope="col">@sortablelink('shipType', 'Ship Type')</th>
<th scope="col">@sortablelink('shipOwner', 'Ship Owner')</th> <th scope="col">@sortablelink('shipOwner', 'Ship Owner')</th>
<th scope="col">@sortablelink('shipClass', 'Ship Class')</th>
<th scope="col">Actions</th> <th scope="col">Actions</th>
</tr> </tr>
</thead> </thead>
@ -70,6 +71,7 @@
<td>{{ $ship->shipName }}</td> <td>{{ $ship->shipName }}</td>
<td>{{ $ship->shipType }}</td> <td>{{ $ship->shipType }}</td>
<td>{{ $ship->shipOwner }}</td> <td>{{ $ship->shipOwner }}</td>
<td>{{ $ship->shipClass }}</td>
<td> <td>
<button type="button" class="btn bi bi-wrench" data-target="#editShip-{{ $ship->id }}" data-toggle="modal"><x-bi-tools/></button> <button type="button" class="btn bi bi-wrench" data-target="#editShip-{{ $ship->id }}" data-toggle="modal"><x-bi-tools/></button>
<button type="button" class="btn" data-target="#deleteShip-{{ $ship->id }}" data-toggle="modal"><x-bi-trash/></button> <button type="button" class="btn" data-target="#deleteShip-{{ $ship->id }}" data-toggle="modal"><x-bi-trash/></button>