How to return validation error when it's failed

Posted 1 month ago by mostafalaravel

Hello ,

I use postman to react with my Restfull API , the validation works fine except when it's failed I don't receive any error message to indicate in which part (name or ...).

    public function store(Request $request)
    {
        $rules = [
            'name' => 'required|min:6|max:50|unique:permissions',
        ];

        $this->validate($request, $rules);
       
        $data = $request->all();
        $data['slug'] = Str::slug($request->name);

        $permission = Permission::create($data);
        return response()->json(['data' => $permission], 201);


    }

Thanks

Please sign in or create an account to participate in this conversation.