Some checks reported errors
		
		
	
	continuous-integration/drone/push Build was killed
				
			
		
			
				
	
	
		
			73 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			73 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Http\Controllers;
 | |
| 
 | |
| use App\Models\Ships;
 | |
| use Illuminate\Support\Facades\DB;
 | |
| use Illuminate\Support\Facades\Log;
 | |
| use Illuminate\Support\Str;
 | |
| use Illuminate\Http\Request;
 | |
| 
 | |
| class ShipsController extends Controller
 | |
| {
 | |
|     public function index(){
 | |
|         $ships = \App\Models\Ships::sortable()->paginate(10);
 | |
|         return view('ships.index', compact('ships'));
 | |
|     }
 | |
| 
 | |
|     public function add(Request $request){
 | |
| 
 | |
|         if($request->input('addShip')) {
 | |
|             try {
 | |
|                 $ship = new Ships;
 | |
|                 $ship->id = Str::uuid()->toString();
 | |
|                 $ship->shipId = strtoupper(request('shipId'));
 | |
|                 $ship->shipName = request('shipName');
 | |
|                 $ship->shipOwner = request('shipOwner');
 | |
|                 $ship->shipType = request('shipType');
 | |
|                 $ship->created_at = now();
 | |
|                 $ship->save();
 | |
|             }catch(\Exception $e){
 | |
|                 session()->flash('error', 'Failed to create record.');
 | |
|                 Log::error($e);
 | |
|                 return redirect('/');
 | |
| 
 | |
|             }
 | |
|             session()->flash('success', 'Record created successfully.');
 | |
|             return redirect('/');
 | |
|         }
 | |
| 
 | |
|         if($request->input('deleteShip')) {
 | |
|             try {
 | |
|                 DB::table('ships')->where('id', $request->get('deleteShip'))->delete();
 | |
|             }catch(\Exception $e){
 | |
|                 Log::error($e);
 | |
|                 session()->flash('error', 'Failed to delete record.');
 | |
|                 return redirect('/');
 | |
|             }
 | |
| 
 | |
|             session()->flash('success', 'Record deleted successfully.');
 | |
|             return redirect('/');
 | |
|         }
 | |
| 
 | |
|         if($request->input('editShip')) {
 | |
|             try {
 | |
|                 DB::table('ships')->where('id', $request->get('editShip'))->update(array(
 | |
|                     'shipId' => strtoupper(request('shipId')),
 | |
|                     'shipName' => request('shipName'),
 | |
|                     'shipOwner' => request('shipOwner'),
 | |
|                     'shipType' => request('shipType')
 | |
|                 ));
 | |
|             }catch(\Exception $e){
 | |
|                 Log::error($e);
 | |
|                 session()->flash('error', 'Failed to update record. Is it possible that the ship ID is not unique?');
 | |
|                 return redirect('/');
 | |
|             }
 | |
| 
 | |
|             session()->flash('success', 'Record edited successfully.');
 | |
|             return redirect('/');
 | |
|         }
 | |
| 
 | |
|     }
 | |
| }
 |