| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace App\Http\Requests;
- use Illuminate\Foundation\Http\FormRequest;
- class UnitRequest extends FormRequest
- {
- public function rules(): array
- {
- $isCreate = $this->isMethod('POST');
- $rules = [
- 'fantasy_name' => 'sometimes|required|string|max:255',
- 'social_reason' => 'sometimes|required|string|max:255',
- 'cnpj' => 'sometimes|required|string|max:20',
- 'state_registration' => 'sometimes|nullable|string|max:50',
- 'name_responsible' => 'sometimes|required|string|max:255',
- 'street' => 'sometimes|required|string|max:255',
- 'address_number' => 'sometimes|nullable|string|max:20',
- 'postal_code' => 'sometimes|required|string|max:9',
- 'neighborhood' => 'sometimes|required|string|max:255',
- 'complement' => 'sometimes|nullable|string|max:255',
- 'city_id' => 'sometimes|required|integer|exists:cities,id',
- 'state_id' => 'sometimes|required|integer|exists:states,id',
- 'email' => 'sometimes|required|email|max:255',
- 'secondary_email' => 'sometimes|nullable|email|max:255',
- 'phone_number' => 'sometimes|required|string|max:20',
- 'cell_number' => 'sometimes|nullable|string|max:20',
- 'avatar' => 'sometimes|nullable|image|max:2048',
- ];
- if ($isCreate) {
- $required = [
- 'fantasy_name',
- 'social_reason',
- 'cnpj',
- 'name_responsible',
- 'street',
- 'postal_code',
- 'neighborhood',
- 'city_id',
- 'state_id',
- 'email',
- 'phone_number',
- ];
- foreach ($required as $field) {
- $rules[$field] = str_replace('sometimes|required', 'required', $rules[$field]);
- }
- }
- return $rules;
- }
- }
|