Files
freeu-project/app/Http/Requests/StoreAttachmentsRequest.php
2024-04-24 15:20:53 +05:30

64 lines
1.3 KiB
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StoreAttachmentsRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes()
{
return [
'filename' => 'file',
];
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'lead_id' => 'required',
'url' => 'sometimes|required',
'filename' => 'sometimes|mimes:jpeg,png,jpg,gif,svg,pdf|max:2048',
'type' => 'required'
];
}
public function messages(){
return [
'required' => 'The :attribute field must be required'
];
}
public function validated()
{
if ($this->type == 1) {
$attachmentImage = time() . '.' . $this->filename->extension();
$path = $this->filename->storeAs('files', $attachmentImage);
}
return array_merge(parent::validated(), [
'created_by' => auth()->user()->id
]);
}
}