Search code examples
laravellaravel-8laravel-request

Laravel - Request safe method does not exist


I generated my StorePostRequest using artisan make command.
I defined rules on the rules method doing this:

public function rules()
{
    return [
        'title' => 'required|min:3|max:255',
        'slug' => ['required', Rule::unique('posts', 'slug')],
        'thumbnail' =>'required|image',
        'excerpt' => 'required|min:3',
        'body' => 'required|min:3',
        'category_id' => 'required|exists:categories,id'
    ];
}

However, in my PostController, I'm not able to get validated inputs except thumbnail using the safe()->except('thumbnail') like explained here

I'm getting the error

BadMethodCallException
Method App\Http\Requests\StorePostRequest::safe does not exist.

Solution

  • Using the except() method directly on $request worked. Thanks to @JEJ for his help.

    $request->except('thumbnail');