109 lines
3.4 KiB
PHP
Executable file
109 lines
3.4 KiB
PHP
Executable file
<?php
|
|
|
|
namespace App\Http\Controllers\Settings;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Models\TravelCompany;
|
|
use App\Models\TravelCompanyService;
|
|
use App\Services\Util;
|
|
use Request;
|
|
|
|
class TravelCompanyController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware(['superadmin', '2fa']);
|
|
}
|
|
|
|
public function index($step = false)
|
|
{
|
|
$data = [
|
|
'travel_company' => TravelCompany::all(),
|
|
];
|
|
return view('settings.travel_company.index', $data);
|
|
}
|
|
|
|
|
|
public function detail($id, $step = false)
|
|
{
|
|
if ($id == "new") {
|
|
$model = new TravelCompany();
|
|
$id = 'new';
|
|
$model->active = 1;
|
|
} else {
|
|
$model = TravelCompany::findOrFail($id);
|
|
$id = $model->id;
|
|
}
|
|
|
|
$data = [
|
|
'model' => $model,
|
|
'id' => $id,
|
|
'step' => $step,
|
|
|
|
];
|
|
return view('settings.travel_company.detail', $data);
|
|
}
|
|
|
|
public function update($id)
|
|
{
|
|
|
|
$data = Request::all();
|
|
|
|
|
|
if (isset($data['update-action'])) {
|
|
if ($data['update-action'] === 'save-travel-company-service') {
|
|
$data['active'] = true; //isset($data['active']) ? true : false;
|
|
$travel_company = TravelCompany::findOrFail($id);
|
|
$data['travel_company_id'] = $travel_company->id;
|
|
|
|
if ($data['travel_company_service_id'] === 'new') {
|
|
$model = TravelCompanyService::create($data);
|
|
} else {
|
|
$model = TravelCompanyService::find($data['travel_company_service_id']);
|
|
$model->fill($data);
|
|
$model->save();
|
|
}
|
|
\Session()->flash('alert-save', '1');
|
|
return redirect($data['back']);
|
|
}
|
|
}
|
|
|
|
$data['contact_emails'] = isset($data['contact_emails']) ? Util::_explodeLines($data['contact_emails']) : null;
|
|
if ($id === "new") {
|
|
$model = TravelCompany::create($data);
|
|
} else {
|
|
$model = TravelCompany::find($id);
|
|
$model->fill($data);
|
|
$model->save();
|
|
}
|
|
|
|
\Session()->flash('alert-save', '1');
|
|
return redirect(route('admin_settings_travel_company_detail', [$model->id, $data['action']]));
|
|
}
|
|
|
|
public function delete($id, $del = "travel_company")
|
|
{
|
|
|
|
if ($del === 'travel_country') {
|
|
abort(404, 'Noch keine Funktion');
|
|
$model = TravelCompany::findOrFail($id);
|
|
$model->delete();
|
|
\Session()->flash('alert-success', 'Eintrag gelöscht');
|
|
return redirect()->back();
|
|
}
|
|
|
|
if ($del === 'company_service') {
|
|
$service = TravelCompanyService::findOrFail($id);
|
|
$travel_company = $service->travel_company;
|
|
//check as entry
|
|
if ($service->booking_company_services->count() > 0) {
|
|
\Session()->flash('alert-error', 'Die Leistung kann nicht gelöscht werden, diese hat Einträge bei den Buchungen');
|
|
return redirect(route('admin_settings_travel_company_detail', [$travel_company->id, 'services']));
|
|
}
|
|
$service->delete();
|
|
\Session()->flash('alert-success', 'Eintrag gelöscht');
|
|
return redirect(route('admin_settings_travel_company_detail', [$travel_company->id, 'services']));
|
|
}
|
|
}
|
|
}
|