laravellaravel-formrequest

laravel Form request validation return 404 error


i'm new to laravel , hope someone could help me with this problem ,

i've created a request class to validate my inputs . But when the validation fails it doesn't return any error messages instead showing a 404 error.

my request class , recoverIdRequest

namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class recoverIdRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'dob' => 'required',
            'email' => 'required',
        ];
    }
}

and here's my controller : testController

class testController extends Controller
{
/** 
*
* @param  \App\Http\Requests\recoverIdRequest $request
* @return Illuminate\Http\Response
*/
    public function test(recoverIdRequest $request)
    {
       
      $validated = $request->validated();
    
      
        $dob = $request->input('dob');
        $new_dob = Carbon::parse($dob)->format('Y-m-d');
        $email = $request->input('email');
   }
      
}

and this is the response in postman when the validation fails :

and this is the response in postman when the validation fails :

routes/api.php

Route::group([ 'prefix'=>'modelTesting', ], function() {
    Route::post('test/{id}' [testController::class,'test'])->middleware(['auth:api', 'scope:admin']);
}); 

Solution

  • Resolved

    it was a problem with postman headers,i was able to fix the issue using the following headers :

    Accept: application/json
    X-Requested-With: XMLHttpRequest