taktik - laravel
This commit is contained in:
50
app/Http/Requests/Post/StorePostRequest.php
Normal file
50
app/Http/Requests/Post/StorePostRequest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\Post;
|
||||
|
||||
use App\Http\Requests\InvalidDataResponseTrait;
|
||||
use App\Http\Resources\PostResource;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StorePostRequest extends FormRequest
|
||||
{
|
||||
use InvalidDataResponseTrait;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return static::rulesDefinition();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function rulesDefinition(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'required|string|max:255',
|
||||
'content' => 'required|string',
|
||||
'category_id' => 'nullable|exists:categories,id',
|
||||
'tags' => 'nullable|array',
|
||||
];
|
||||
}
|
||||
|
||||
public function getPost(): PostResource
|
||||
{
|
||||
return PostResource::make($this->all());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user