Added validation logic for booking store and update.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreBooking extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'date' => 'required',
|
||||
'reference' => 'required',
|
||||
'person_or_company' => 'required',
|
||||
'amount' => 'sometimes|required|numeric|min:0',
|
||||
'account_type_id' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'date.required' =>
|
||||
'Die Buchung muss ein Datum haben.',
|
||||
|
||||
'reference.required' =>
|
||||
'Die Buchung muss einen Buchungstext haben.',
|
||||
|
||||
'person_or_company.required' =>
|
||||
'Der Buchung muss eine Person oder Firma zugeordnet werden.',
|
||||
|
||||
'amount.required' =>
|
||||
'Die Buchung muss einen Betrag haben.',
|
||||
'amount.numeric' =>
|
||||
'Der Betrag muss eine Zahl sein.',
|
||||
'amount.min' =>
|
||||
'Der Betrag darf kein Vorzeichen haben. Das Vorzeichen der
|
||||
Buchung wird durch das zugeordnete Konto bestimmt.',
|
||||
|
||||
'account_type_id.required' =>
|
||||
'Der Buchung muss ein Konto zugewiesen werden.'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateBooking extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
// Booking information
|
||||
'booking.date' => 'required',
|
||||
'booking.reference' => 'required',
|
||||
'booking.person_or_company' => 'required',
|
||||
|
||||
// Sub-booking informations
|
||||
'sub_booking.*.reference' =>
|
||||
'required_with:'
|
||||
. 'sub_booking.*.amount,'
|
||||
. 'sub_booking.*.account_type_id,'
|
||||
. 'sub_booking.*.person_target_id,'
|
||||
. 'sub_booking.*.project_id',
|
||||
'sub_booking.*.amount' =>
|
||||
'required_with:'
|
||||
. 'sub_booking.*.reference,'
|
||||
. 'sub_booking.*.account_type_id,'
|
||||
. 'sub_booking.*.person_target_id,'
|
||||
. 'sub_booking.*.project_id'
|
||||
. '|nullable'
|
||||
. '|numeric'
|
||||
. '|min:0',
|
||||
'sub_booking.*.account_type_id' =>
|
||||
'required_with:'
|
||||
. 'sub_booking.*.reference,'
|
||||
. 'sub_booking.*.amount,'
|
||||
. 'sub_booking.*.person_target_id,'
|
||||
. 'sub_booking.*.project_id'
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
// Booking
|
||||
'booking.date.required' =>
|
||||
'Die Buchung muss ein Datum haben.',
|
||||
|
||||
'booking.reference.required' =>
|
||||
'Die Buchung muss einen Buchungstext haben.',
|
||||
|
||||
'booking.person_or_company' =>
|
||||
'Der Buchung muss eine Person oder Firma zugeordnet werden.',
|
||||
|
||||
// Sub-bookings
|
||||
'sub_booking.*.reference.required_with' =>
|
||||
'Die Teilbuchung muss einen Buchungstext haben.',
|
||||
|
||||
'sub_booking.*.amount.required_with' =>
|
||||
'Die Teilbuchung muss einen Betrag haben.',
|
||||
'sub_booking.*.amount.numeric' =>
|
||||
'Der Betrag muss eine Zahl sein.',
|
||||
'sub_booking.*.amount.min' =>
|
||||
'Der Betrag darf kein Vorzeichen haben. Das Vorzeichen Der
|
||||
Teilbuchung wird durch das zugeordnete Konto bestimmt.',
|
||||
|
||||
'sub_booking.*.account_type_id.required_with' =>
|
||||
'Der Teilbuchung muss ein Konto zugewiesen werden.'
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user