-
app/Http/Requests/StoreLinkApiRequest.php
Open in GitHubclass StoreLinkApiRequest extends FormRequest { public function authorize(): bool { return Request::user()->tokenCan('create'); } protected function prepareForValidation(): void { $this->merge([ 'link' => filter_var($this->link, FILTER_VALIDATE_URL) ? $this->link : "https://$this->link", ]); } public function rules(): array { return Link::rules($this->request->get('link')); } public function failedValidation(Validator $validator) { throw new HttpResponseException(response()->json([ 'success' => false, 'message' => 'Validation errors', 'data' => $validator->errors() ], 422)); } }