mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-28 20:21:10 -04:00
add mail sender crud
This commit is contained in:
79
app/Http/Requests/MailSenderRequest.php
Normal file
79
app/Http/Requests/MailSenderRequest.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Http\Requests;
|
||||
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class MailSenderRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$rules = [
|
||||
'name' => [
|
||||
'required',
|
||||
Rule::unique('mail_senders')
|
||||
->where('company_id', $this->header('company'))
|
||||
],
|
||||
'driver' => [
|
||||
'required',
|
||||
],
|
||||
'is_default' => [
|
||||
'nullable'
|
||||
],
|
||||
'bcc' => [
|
||||
'nullable'
|
||||
],
|
||||
'cc' => [
|
||||
'nullable'
|
||||
],
|
||||
'from_address' => [
|
||||
'nullable'
|
||||
],
|
||||
'from_name' => [
|
||||
'nullable'
|
||||
],
|
||||
'settings' => [
|
||||
'nullable'
|
||||
],
|
||||
'settings.*' => [
|
||||
'nullable'
|
||||
]
|
||||
];
|
||||
|
||||
if ($this->isMethod('PUT')) {
|
||||
$rules['name'] = [
|
||||
'nullable',
|
||||
Rule::unique('mail_senders')
|
||||
->ignore($this->route('mail_sender')->id)
|
||||
->where('company_id', $this->header('company'))
|
||||
];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function getMailSenderPayload()
|
||||
{
|
||||
return collect($this->validated())
|
||||
->merge([
|
||||
'company_id' => $this->header('company'),
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user