diff --git a/app/Http/Controllers/CarController.php b/app/Http/Controllers/CarController.php index 8d0bc60..28a4fab 100644 --- a/app/Http/Controllers/CarController.php +++ b/app/Http/Controllers/CarController.php @@ -224,48 +224,40 @@ class CarController extends Controller private function getWithCustomSort($cars, string $sortBy, string $direction) { - switch($sortBy) { - case 'name': - return $cars - ->leftJoin('car_models', 'cars.car_model_id', '=', 'car_models.id') - ->leftJoin('brands', 'car_models.brand_id', '=', 'brands.id') - ->orderBy('brands.name', $direction) - ->orderBy('car_models.name', $direction); - case 'initial_date': - return $cars->orderBy('initial_date', $direction); - case 'stammnummer': - return $cars->orderBy('stammnummer', $direction); - case 'buy_contract.date': - return $cars - ->leftJoin('contracts', function($join) { - $join->on('contracts.car_id', '=', 'cars.id') - ->on('contracts.id', '=', DB::raw("(SELECT id from contracts WHERE contracts.car_id = cars.id and type = '0' order by date desc limit 1)")); - }) - ->orderBy('contracts.date', $direction); - case 'buy_contract.price': - return $cars - ->leftJoin('contracts', function($join) { - $join->on('contracts.car_id', '=', 'cars.id') + return match ($sortBy) { + 'name' => $cars + ->leftJoin('car_models', 'cars.car_model_id', '=', 'car_models.id') + ->leftJoin('brands', 'car_models.brand_id', '=', 'brands.id') + ->orderBy('brands.name', $direction) + ->orderBy('car_models.name', $direction), + 'initial_date' => $cars->orderBy('initial_date', $direction), + 'stammnummer' => $cars->orderBy('stammnummer', $direction), + 'buy_contract.date' => $cars + ->leftJoin('contracts', function($join) { + $join->on('contracts.car_id', '=', 'cars.id') ->on('contracts.id', '=', DB::raw("(SELECT id from contracts WHERE contracts.car_id = cars.id and type = '0' order by date desc limit 1)")); - }) - ->orderBy('contracts.price', $direction); - case 'sell_contract.date': - return $cars - ->leftJoin('contracts', function($join) { - $join->on('contracts.car_id', '=', 'cars.id') - ->on('contracts.id', '=', DB::raw("(SELECT id from contracts WHERE contracts.car_id = cars.id and type = '1' order by date desc limit 1)")); - }) - ->orderBy('contracts.date', $direction); - case 'sell_contract.price': - return $cars - ->leftJoin('contracts', function($join) { - $join->on('contracts.car_id', '=', 'cars.id') + }) + ->orderBy('contracts.date', $direction), + 'buy_contract.price' => $cars + ->leftJoin('contracts', function($join) { + $join->on('contracts.car_id', '=', 'cars.id') + ->on('contracts.id', '=', DB::raw("(SELECT id from contracts WHERE contracts.car_id = cars.id and type = '0' order by date desc limit 1)")); + }) + ->orderBy('contracts.price', $direction), + 'sell_contract.date' => $cars + ->leftJoin('contracts', function($join) { + $join->on('contracts.car_id', '=', 'cars.id') ->on('contracts.id', '=', DB::raw("(SELECT id from contracts WHERE contracts.car_id = cars.id and type = '1' order by date desc limit 1)")); - }) - ->orderBy('contracts.price', $direction); - default: - return $cars->orderBy('initial_date', $direction); - } + }) + ->orderBy('contracts.date', $direction), + 'sell_contract.price' => $cars + ->leftJoin('contracts', function($join) { + $join->on('contracts.car_id', '=', 'cars.id') + ->on('contracts.id', '=', DB::raw("(SELECT id from contracts WHERE contracts.car_id = cars.id and type = '1' order by date desc limit 1)")); + }) + ->orderBy('contracts.price', $direction), + default => $cars->orderBy('initial_date', $direction), + }; } private function getSortBy(Request $request, $defaultSort) diff --git a/app/Http/Controllers/ContactController.php b/app/Http/Controllers/ContactController.php index 38093ab..7cefc57 100644 --- a/app/Http/Controllers/ContactController.php +++ b/app/Http/Controllers/ContactController.php @@ -130,18 +130,13 @@ class ContactController extends Controller private function getWithCustomSort($contacts, string $sortBy, string $direction) { - switch($sortBy) { - case 'company': - return $contacts->orderBy('company', $direction); - case 'fullCity': - return $contacts->orderBy('city', $direction); - case 'email': - return $contacts->orderBy('email', $direction); - case 'address': - return $contacts->orderBy('address', $direction); - default: - return $contacts->orderByName($direction); - } + return match ($sortBy) { + 'company' => $contacts->orderBy('company', $direction), + 'fullCity' => $contacts->orderBy('city', $direction), + 'email' => $contacts->orderBy('email', $direction), + 'address' => $contacts->orderBy('address', $direction), + default => $contacts->orderByName($direction), + }; } private function getSortBy(Request $request) diff --git a/app/Models/Contract.php b/app/Models/Contract.php index b63dcc0..fcad06e 100644 --- a/app/Models/Contract.php +++ b/app/Models/Contract.php @@ -77,20 +77,14 @@ class Contract extends Model public function getInsuranceTypeFormattedAttribute() { - switch ($this->insurance_type) { - case InsuranceType::QBase: - return 'Q Basis'; - case InsuranceType::OneStar: - return '1 Stern'; - case InsuranceType::ThreeStar: - return '3 Stern'; - case InsuranceType::FiveStar: - return '5 Stern'; - case InsuranceType::FiveStarPlus: - return '5 Stern+'; - default: - return 'Nein'; - } + return match ($this->insurance_type) { + InsuranceType::QBase => 'Q Basis', + InsuranceType::OneStar => '1 Stern', + InsuranceType::ThreeStar => '3 Stern', + InsuranceType::FiveStar => '5 Stern', + InsuranceType::FiveStarPlus => '5 Stern+', + default => 'Nein', + }; } public function getDeletedAtAttribute($deleted_at) diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 85b40e7..ab8084c 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -43,26 +43,20 @@ class Payment extends Model public function getTypeAttribute($type) { - switch ($type) { - case PaymentType::Transaction(): - return 'Banküberweisung'; - case PaymentType::Cash(): - return 'Barzahlung'; - default: - return 'Überweisung via Cembra'; - }; + return match ($type) { + PaymentType::Transaction() => 'Banküberweisung', + PaymentType::Cash() => 'Barzahlung', + default => 'Überweisung via Cembra', + };; } public function getTypeTextAttribute() { - switch ($this->type) { - case 'Banküberweisung': - return 'via Banküberweisung erhalten'; - case 'Barzahlung': - return 'in bar erhalten'; - default: - return 'via Cembra-Überweisung erhalten'; - }; + return match ($this->type) { + 'Banküberweisung' => 'via Banküberweisung erhalten', + 'Barzahlung' => 'in bar erhalten', + default => 'via Cembra-Überweisung erhalten', + };; } public function getPrintLinkAttribute() diff --git a/routes/web.php b/routes/web.php index 55099a8..e157056 100644 --- a/routes/web.php +++ b/routes/web.php @@ -9,7 +9,6 @@ use App\Http\Controllers\PaymentController; use App\Http\Controllers\ContractController; use App\Http\Controllers\DocumentController; use Illuminate\Support\Facades\Route; - Route::middleware(['auth:sanctum', 'verified'])->group(function () { Route::get('/', [ContractController::class, 'dashboard'])->name('dashboard'); @@ -87,4 +86,4 @@ Route::middleware(['auth:sanctum', 'verified'])->group(function () { Route::post('brands', [BrandController::class, 'store'])->name('brands.store'); Route::post('models', [CarModelController::class, 'store'])->name('models.store'); -}); \ No newline at end of file +});