In my Laravel (5.1) project I need to create a Request for validating a form.
But for this request, i would like to merge two different requests :
The first request :
class AdvertisementRequest extends Request {
public function authorize()
{
return true;
}
public function rules()
{
return [
'ads_type' => 'required|numeric|in:0,1',
'category' => 'required|numeric|exists:categories,id',
'title' => 'required|alpha_num|max:45',
'description' => 'required|alpha_num|max:2000',
'price' => 'required|numeric',
];
}
}
The second request :
class UserRegisterRequest extends Request {
public function authorize()
{
return true;
}
public function rules()
{
$rules = [
'form_type' => 'required|numeric|in:0,1',
'user_type' => 'required|numeric|in:0,1',
'phone' => 'required|phone_number',
'region' => 'required|numeric|exists:regions,id',
'department' => 'required|numeric|exists:departments,code',
'postal_code' => 'required|postal_code',
'city' => 'alpha|max:45',
'id_city' => 'required|numeric|exists:cities,id',
'last_name' => 'required|alpha_sp|max:45',
'first_name' => 'required|alpha_sp|max:45',
'pseudo' => 'required|alpha|max:45|unique:users',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|alpha_num|min:6|max:45',
];
return $rules;
}
}
And i would like to create a third request which combining the two other like that :
class UserAdvertisementRegisterRequest extends Request {
public function authorize()
{
return true;
}
public function rules()
{
$rules = [
'ads_type' => 'required|numeric|in:0,1',
'category' => 'required|numeric|exists:categories,id',
'title' => 'required|alpha_num|max:45',
'description' => 'required|alpha_num|max:2000',
'price' => 'required|numeric',
'form_type' => 'required|numeric|in:0,1',
'user_type' => 'required|numeric|in:0,1',
'phone' => 'required|phone_number',
'region' => 'required|numeric|exists:regions,id',
'department' => 'required|numeric|exists:departments,code',
'postal_code' => 'required|postal_code',
'city' => 'alpha|max:45',
'id_city' => 'required|numeric|exists:cities,id',
'last_name' => 'required|alpha_sp|max:45',
'first_name' => 'required|alpha_sp|max:45',
'pseudo' => 'required|alpha|max:45|unique:users',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|alpha_num|min:6|max:45',
];
return $rules;
}
}
Is there any solution for do that without duplicate my code ?
Sorry for my bad english :/.
Thank you in advance for you reply !