php Laraval 7中的表单请求规则不起作用

tf7tbtn2  于 2023-02-18  发布在  PHP
关注(0)|答案(1)|浏览(129)

我用的是拉瑞威7号
我有一个已生成的请求,但所需的规则不起作用。请求发送回来,没有任何错误。
并且dd()也没有示出请求数据。

    • 功能:**
public function store(StoreRequest $request)
    {
        dd($request->all());
        if (!auth()->user()->can('add-users')) {
            abort(401);
        }
        try {
            $userStatus = app(CreateUser::class)->execute($request->all());
            if ($userStatus == true) {
                return redirect()->back()->with('success', 'User successfully created.');
            } else {
                return redirect()->back()->with('error', 'Oops Something went wrong!');
            }
        } catch (\Exception $ex) {
            return redirect()->back()->with('error', $ex->getMessage());
        }
    }
    • 请求代码:**
class StoreRequest 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 [
            'name' => ['required','string','max:255'],
            'email' => ['required','string','max:255'],
            'password' => 'required',
            'organization_id' => 'required'
        ];
    }
}

如果我使用Illuminate\Http\Request显示请求数据但不验证数据。
你知道吗?

7uhlpewt

7uhlpewt1#

你能试试这个吗

public function rules()
{
    return [
        'name' => 'required|string|max:255',
        'email' => 'required|string|max:255',
        'password' => 'required',
        'organization_id' => 'required'
    ];
}

相关问题