Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

guillaumebriday/laravel-blog

1797 stars
1 code files
View guillaumebriday/laravel-blog on GitHub

app/Http/Requests/Admin/PostsRequest.php

Open in GitHub
use App\Rules\CanBeAuthor;
use Carbon\Carbon;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Str;
 
class PostsRequest extends FormRequest
{
public function authorize()
{
return true;
}
 
protected function prepareForValidation(): void
{
$this->merge([
'slug' => Str::slug($this->input('title'))
]);
 
$this->merge([
'posted_at' => Carbon::parse($this->input('posted_at'))
]);
}
 
public function rules(): array
{
return [
'title' => 'required',
'content' => 'required',
'posted_at' => 'required|date',
'thumbnail_id' => 'nullable|exists:media,id',
'author_id' => ['required', 'exists:users,id', new CanBeAuthor],
'slug' => 'unique:posts,slug,' . (optional($this->post)->id ?: 'NULL'),
];
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.