47 lines
955 B
PHP
Executable File
47 lines
955 B
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Requests\Dashboard\UsefulInfoRequest;
|
|
|
|
use App\Models\UsefulInfo;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class Update extends FormRequest
|
|
{
|
|
/**
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
'name_uz' => 'required|string',
|
|
'name_ru' => 'required|string',
|
|
'image' => 'nullable|image',
|
|
'position' => 'nullable|integer'
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getName(): array
|
|
{
|
|
return [
|
|
'uz' => $this->get('name_uz'),
|
|
'ru' => $this->get('name_ru')
|
|
];
|
|
}
|
|
|
|
public function getPosition(): int|null
|
|
{
|
|
if ($this->position) {
|
|
return $this->get('position');
|
|
} else {
|
|
if (UsefulInfo::count() === 0) {
|
|
return 0;
|
|
}
|
|
return UsefulInfo::max('position') + 1;
|
|
}
|
|
}
|
|
}
|