Convert `switch` to `match`
parent
64b166716e
commit
3de473c795
|
|
@ -224,48 +224,40 @@ class CarController extends Controller
|
||||||
|
|
||||||
private function getWithCustomSort($cars, string $sortBy, string $direction)
|
private function getWithCustomSort($cars, string $sortBy, string $direction)
|
||||||
{
|
{
|
||||||
switch($sortBy) {
|
return match ($sortBy) {
|
||||||
case 'name':
|
'name' => $cars
|
||||||
return $cars
|
->leftJoin('car_models', 'cars.car_model_id', '=', 'car_models.id')
|
||||||
->leftJoin('car_models', 'cars.car_model_id', '=', 'car_models.id')
|
->leftJoin('brands', 'car_models.brand_id', '=', 'brands.id')
|
||||||
->leftJoin('brands', 'car_models.brand_id', '=', 'brands.id')
|
->orderBy('brands.name', $direction)
|
||||||
->orderBy('brands.name', $direction)
|
->orderBy('car_models.name', $direction),
|
||||||
->orderBy('car_models.name', $direction);
|
'initial_date' => $cars->orderBy('initial_date', $direction),
|
||||||
case 'initial_date':
|
'stammnummer' => $cars->orderBy('stammnummer', $direction),
|
||||||
return $cars->orderBy('initial_date', $direction);
|
'buy_contract.date' => $cars
|
||||||
case 'stammnummer':
|
->leftJoin('contracts', function($join) {
|
||||||
return $cars->orderBy('stammnummer', $direction);
|
$join->on('contracts.car_id', '=', 'cars.id')
|
||||||
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')
|
|
||||||
->on('contracts.id', '=', DB::raw("(SELECT id from contracts WHERE contracts.car_id = cars.id and type = '0' order by date desc limit 1)"));
|
->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);
|
->orderBy('contracts.date', $direction),
|
||||||
case 'sell_contract.date':
|
'buy_contract.price' => $cars
|
||||||
return $cars
|
->leftJoin('contracts', function($join) {
|
||||||
->leftJoin('contracts', function($join) {
|
$join->on('contracts.car_id', '=', 'cars.id')
|
||||||
$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)"));
|
||||||
->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),
|
||||||
->orderBy('contracts.date', $direction);
|
'sell_contract.date' => $cars
|
||||||
case 'sell_contract.price':
|
->leftJoin('contracts', function($join) {
|
||||||
return $cars
|
$join->on('contracts.car_id', '=', 'cars.id')
|
||||||
->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)"));
|
->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);
|
->orderBy('contracts.date', $direction),
|
||||||
default:
|
'sell_contract.price' => $cars
|
||||||
return $cars->orderBy('initial_date', $direction);
|
->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)
|
private function getSortBy(Request $request, $defaultSort)
|
||||||
|
|
|
||||||
|
|
@ -130,18 +130,13 @@ class ContactController extends Controller
|
||||||
|
|
||||||
private function getWithCustomSort($contacts, string $sortBy, string $direction)
|
private function getWithCustomSort($contacts, string $sortBy, string $direction)
|
||||||
{
|
{
|
||||||
switch($sortBy) {
|
return match ($sortBy) {
|
||||||
case 'company':
|
'company' => $contacts->orderBy('company', $direction),
|
||||||
return $contacts->orderBy('company', $direction);
|
'fullCity' => $contacts->orderBy('city', $direction),
|
||||||
case 'fullCity':
|
'email' => $contacts->orderBy('email', $direction),
|
||||||
return $contacts->orderBy('city', $direction);
|
'address' => $contacts->orderBy('address', $direction),
|
||||||
case 'email':
|
default => $contacts->orderByName($direction),
|
||||||
return $contacts->orderBy('email', $direction);
|
};
|
||||||
case 'address':
|
|
||||||
return $contacts->orderBy('address', $direction);
|
|
||||||
default:
|
|
||||||
return $contacts->orderByName($direction);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getSortBy(Request $request)
|
private function getSortBy(Request $request)
|
||||||
|
|
|
||||||
|
|
@ -77,20 +77,14 @@ class Contract extends Model
|
||||||
|
|
||||||
public function getInsuranceTypeFormattedAttribute()
|
public function getInsuranceTypeFormattedAttribute()
|
||||||
{
|
{
|
||||||
switch ($this->insurance_type) {
|
return match ($this->insurance_type) {
|
||||||
case InsuranceType::QBase:
|
InsuranceType::QBase => 'Q Basis',
|
||||||
return 'Q Basis';
|
InsuranceType::OneStar => '1 Stern',
|
||||||
case InsuranceType::OneStar:
|
InsuranceType::ThreeStar => '3 Stern',
|
||||||
return '1 Stern';
|
InsuranceType::FiveStar => '5 Stern',
|
||||||
case InsuranceType::ThreeStar:
|
InsuranceType::FiveStarPlus => '5 Stern+',
|
||||||
return '3 Stern';
|
default => 'Nein',
|
||||||
case InsuranceType::FiveStar:
|
};
|
||||||
return '5 Stern';
|
|
||||||
case InsuranceType::FiveStarPlus:
|
|
||||||
return '5 Stern+';
|
|
||||||
default:
|
|
||||||
return 'Nein';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDeletedAtAttribute($deleted_at)
|
public function getDeletedAtAttribute($deleted_at)
|
||||||
|
|
|
||||||
|
|
@ -43,26 +43,20 @@ class Payment extends Model
|
||||||
public function getTypeAttribute($type)
|
public function getTypeAttribute($type)
|
||||||
{
|
{
|
||||||
|
|
||||||
switch ($type) {
|
return match ($type) {
|
||||||
case PaymentType::Transaction():
|
PaymentType::Transaction() => 'Banküberweisung',
|
||||||
return 'Banküberweisung';
|
PaymentType::Cash() => 'Barzahlung',
|
||||||
case PaymentType::Cash():
|
default => 'Überweisung via Cembra',
|
||||||
return 'Barzahlung';
|
};;
|
||||||
default:
|
|
||||||
return 'Überweisung via Cembra';
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTypeTextAttribute()
|
public function getTypeTextAttribute()
|
||||||
{
|
{
|
||||||
switch ($this->type) {
|
return match ($this->type) {
|
||||||
case 'Banküberweisung':
|
'Banküberweisung' => 'via Banküberweisung erhalten',
|
||||||
return 'via Banküberweisung erhalten';
|
'Barzahlung' => 'in bar erhalten',
|
||||||
case 'Barzahlung':
|
default => 'via Cembra-Überweisung erhalten',
|
||||||
return 'in bar erhalten';
|
};;
|
||||||
default:
|
|
||||||
return 'via Cembra-Überweisung erhalten';
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPrintLinkAttribute()
|
public function getPrintLinkAttribute()
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ use App\Http\Controllers\PaymentController;
|
||||||
use App\Http\Controllers\ContractController;
|
use App\Http\Controllers\ContractController;
|
||||||
use App\Http\Controllers\DocumentController;
|
use App\Http\Controllers\DocumentController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
Route::middleware(['auth:sanctum', 'verified'])->group(function () {
|
Route::middleware(['auth:sanctum', 'verified'])->group(function () {
|
||||||
Route::get('/', [ContractController::class, 'dashboard'])->name('dashboard');
|
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('brands', [BrandController::class, 'store'])->name('brands.store');
|
||||||
Route::post('models', [CarModelController::class, 'store'])->name('models.store');
|
Route::post('models', [CarModelController::class, 'store'])->name('models.store');
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue