48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Coupons;
|
|
|
|
use App\Http\Resources\StatusResource;
|
|
use Illuminate\Contracts\Validation\Validator;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
|
|
|
class PrintRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
// TODO : Validate coupons formats
|
|
return [
|
|
'refcamp' => 'string|exists:campagne,camp_id|required',
|
|
'hashcode' => 'string|exists:customers,hashcode|required',
|
|
'coupons' => 'required',
|
|
'type' => 'nullable|in:stream,dl'
|
|
];
|
|
}
|
|
|
|
protected function failedValidation(Validator $validator)
|
|
{
|
|
if ($this->wantsJson()) {
|
|
throw new HttpResponseException(response()->json(new StatusResource([
|
|
'status' => 'KO',
|
|
'code' => 422,
|
|
'message' => $validator->errors()->messages()
|
|
]), 422));
|
|
}
|
|
}
|
|
}
|