PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.9
Yatra – Travel Booking & Tour Operator Software v3.0.9
3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 All 83 releases
yatra / app / Http / Requests / TripRequest.php

TripRequest.php in Yatra – Travel Booking & Tour Operator Software 3.0.9, at app/Http/Requests/TripRequest.php

59 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Yatra\Http\Requests;
6
7 /**
8 * Trip Request
9 * Validates trip creation/update requests
10 */
11 class TripRequest extends BaseRequest
12 {
13 /**
14 * Validation rules
15 */
16 protected function rules(): array
17 {
18 return [
19 'title' => 'required|string|max:255',
20 'slug' => 'required|string|max:255',
21 'description' => 'nullable|string',
22 'price' => 'nullable|numeric|min:0',
23 'status' => 'nullable|string|in:draft,active,inactive',
24 ];
25 }
26
27 /**
28 * Validate the request
29 */
30 public function validate(): bool
31 {
32 $rules = $this->rules();
33
34 foreach ($rules as $field => $rule) {
35 $ruleParts = explode('|', $rule);
36
37 foreach ($ruleParts as $rulePart) {
38 if ($rulePart === 'required' && !isset($this->data[$field])) {
39 $this->errors[$field][] = "The {$field} field is required.";
40 }
41
42 if (strpos($rulePart, 'max:') === 0 && isset($this->data[$field])) {
43 $max = (int) str_replace('max:', '', $rulePart);
44 if (strlen($this->data[$field]) > $max) {
45 $this->errors[$field][] = "The {$field} field must not exceed {$max} characters.";
46 }
47 }
48
49 if ($rulePart === 'numeric' && isset($this->data[$field]) && !is_numeric($this->data[$field])) {
50 $this->errors[$field][] = "The {$field} field must be numeric.";
51 }
52 }
53 }
54
55 return $this->isValid();
56 }
57 }
58
59