79 lines
1.8 KiB
PHP
Executable file
79 lines
1.8 KiB
PHP
Executable file
<?php
|
|
|
|
namespace App\Http\Controllers\Settings;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Models\Airline;
|
|
use App\Models\Booking;
|
|
use App\Services\Util;
|
|
use Request;
|
|
|
|
class AirlineController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware(['superadmin', '2fa']);
|
|
}
|
|
|
|
public function index($step = false)
|
|
{
|
|
$data = [
|
|
'airline' => Airline::all(),
|
|
];
|
|
return view('settings.airline.index', $data);
|
|
}
|
|
|
|
public function detail($id, $step = false)
|
|
{
|
|
if($id === "new") {
|
|
$model = new Airline();
|
|
$id = 'new';
|
|
}else{
|
|
$model = Airline::findOrFail($id);
|
|
$id = $model->id;
|
|
}
|
|
|
|
$data = [
|
|
'model' => $model,
|
|
'id' => $id,
|
|
'step' => $step,
|
|
];
|
|
return view('settings.airline.detail', $data);
|
|
}
|
|
|
|
public function update($id){
|
|
|
|
$data = Request::all();
|
|
|
|
|
|
$data['contact_emails'] = isset($data['contact_emails']) ? Util::_explodeLines($data['contact_emails']) : null;
|
|
|
|
if($id === "new"){
|
|
$model = Airline::create($data);
|
|
}else{
|
|
$model = Airline::find($id);
|
|
$model->fill($data);
|
|
$model->save();
|
|
}
|
|
|
|
\Session()->flash('alert-save', '1');
|
|
return redirect(route('admin_settings_airline_detail', [$model->id]));
|
|
}
|
|
|
|
public function delete($id){
|
|
|
|
$model = Airline::findOrFail($id);
|
|
|
|
if(Booking::where('airline_id', $model->id)->count()){
|
|
\Session()->flash('alert-error', 'Fehler: Airline in Buchnungen verwendet.');
|
|
return redirect()->back();
|
|
}
|
|
$model->delete();
|
|
\Session()->flash('alert-success', 'Eintrag gelöscht');
|
|
return redirect()->back();
|
|
}
|
|
|
|
}
|
|
|
|
|