/
home
/
sditechnicalteam
/
public_html
/
app
/
Http
/
Requests
/
Product
/
File Upload :
llllll
Current File: //home/sditechnicalteam/public_html/app/Http/Requests/Product/UpdateProductRequest.php
<?php namespace App\Http\Requests\Product; use App\Http\Requests\CoreRequest; use App\Models\CustomField; class UpdateProductRequest extends CoreRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { return true; } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { $rules = [ 'name' => 'required', 'price' => 'required|numeric', 'downloadable_file' => 'nullable|file', ]; if (request()->get('custom_fields_data')) { $fields = request()->get('custom_fields_data'); foreach ($fields as $key => $value) { $idarray = explode('_', $key); $id = end($idarray); $customField = CustomField::findOrFail($id); if ($customField->required == 'yes' && (is_null($value) || $value == '')) { $rules['custom_fields_data['.$key.']'] = 'required'; } } } return $rules; } public function attributes() { $attributes = []; if (request()->get('custom_fields_data')) { $fields = request()->get('custom_fields_data'); foreach ($fields as $key => $value) { $idarray = explode('_', $key); $id = end($idarray); $customField = CustomField::findOrFail($id); if ($customField->required == 'yes') { $attributes['custom_fields_data['.$key.']'] = $customField->label; } } } return $attributes; } }
Copyright ©2k19 -
Hexid
|
Tex7ure