62 lines
1.7 KiB
PHP
62 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Models\Admin\Testimonial;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class UpdateTestimonialRequest extends FormRequest
|
|
{
|
|
/**
|
|
* 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()
|
|
{
|
|
return [
|
|
'client_name' => 'required',
|
|
'client_designation_company_name' => 'required',
|
|
'description' => 'required',
|
|
];
|
|
}
|
|
|
|
public function messages(){
|
|
return [
|
|
'required' => 'The :attribute field is required.',
|
|
];
|
|
}
|
|
|
|
public function validated()
|
|
{
|
|
$testimonials = Testimonial::find($this->testimonial_id);
|
|
$image = basename($testimonials->client_image);
|
|
if($this->client_images === 'male.jpg' || $this->client_images === 'female.png'){
|
|
$image = $this->client_images;
|
|
}
|
|
if($this->client_images === "One"){
|
|
if($this->has('client_images_one')){
|
|
if (\File::exists(public_path('/uploads/testimonials/images/' . $testimonials->client_image . ''))) {
|
|
\File::delete(public_path('/uploads/testimonials/images/' . $testimonials->client_image . ''));
|
|
}
|
|
$image = time() . '.' . $this->client_images_one->extension();
|
|
$this->client_images_one->move(public_path('/uploads/testimonials/images'), $image);
|
|
}
|
|
}
|
|
return array_merge(parent::validated(), [
|
|
'rating' => $this->rating,
|
|
'client_image' => $image
|
|
]);
|
|
}
|
|
}
|