Convert `switch` to `match`
parent
64b166716e
commit
3de473c795
|
|
@ -224,48 +224,40 @@ class CarController extends Controller
|
|||
|
||||
private function getWithCustomSort($cars, string $sortBy, string $direction)
|
||||
{
|
||||
switch($sortBy) {
|
||||
case 'name':
|
||||
return $cars
|
||||
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);
|
||||
case 'initial_date':
|
||||
return $cars->orderBy('initial_date', $direction);
|
||||
case 'stammnummer':
|
||||
return $cars->orderBy('stammnummer', $direction);
|
||||
case 'buy_contract.date':
|
||||
return $cars
|
||||
->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.date', $direction);
|
||||
case 'buy_contract.price':
|
||||
return $cars
|
||||
->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);
|
||||
case 'sell_contract.date':
|
||||
return $cars
|
||||
->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.date', $direction);
|
||||
case 'sell_contract.price':
|
||||
return $cars
|
||||
->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:
|
||||
return $cars->orderBy('initial_date', $direction);
|
||||
}
|
||||
->orderBy('contracts.price', $direction),
|
||||
default => $cars->orderBy('initial_date', $direction),
|
||||
};
|
||||
}
|
||||
|
||||
private function getSortBy(Request $request, $defaultSort)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue