93 lines
2.7 KiB
PHP
93 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\News;
|
|
|
|
use App\Http\Requests\Bo\UpdateMiniCrudRequest;
|
|
use Illuminate\Support\Str;
|
|
|
|
class StoreNewsRequest extends UpdateMiniCrudRequest
|
|
{
|
|
/**
|
|
* The model parameter name
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $modelName = 'news';
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize()
|
|
{
|
|
return auth('backend')->check();
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function prepareForValidation()
|
|
{
|
|
$this->merge([
|
|
'slug' => Str::slug(strip_tags($this->name)),
|
|
'status' => $this->status ? true : false,
|
|
'publish_at' => $this->publish_at ? \str_replace('T', ' ', $this->publish_at) : null,
|
|
'unpublish_at' => $this->unpublish_at ? \str_replace('T', ' ', $this->unpublish_at) : null,
|
|
'locales' => \collect($this->locales)->filter()->unique()->all()
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
$rules = [
|
|
'seo_title' => 'required|min:3|max:70',
|
|
'seo_description' => 'required|min:50|max:160',
|
|
|
|
'slug' => 'unique_translation:news',
|
|
'title' => 'required|min:3|max:70',
|
|
'subtitle' => 'required|min:3|max:70',
|
|
'content' => 'required|string|min:15',
|
|
'locales' => 'required|array',
|
|
'locales.*' => ['required', \sprintf('in:%s', \implode(',', \config('app.locales')))],
|
|
'data' => 'present|array',
|
|
'data.*' => 'required|array',
|
|
'data.bloc_1_display_picture.value' => 'required|accepted',
|
|
|
|
'status' => 'required|boolean',
|
|
'publish_at' => 'sometimes|nullable|date',
|
|
'unpublish_at' => 'sometimes|nullable|date'
|
|
];
|
|
return \array_merge(
|
|
parent::rules(),
|
|
$rules
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes()
|
|
{
|
|
return [
|
|
'seo_title' => trans('titre') . ' seo',
|
|
'seo_description' => trans('description') . ' seo',
|
|
|
|
'slug' => trans('slug of the news'),
|
|
'subtitle' => trans('subtitle of the news'),
|
|
'content' => trans('content of the news'),
|
|
'data' => trans('values of the data'),
|
|
'data.*.value' => trans('value of the data'),
|
|
'data.bloc_1_display_picture.value' => trans('visibility of the first picture')
|
|
];
|
|
}
|
|
}
|