jeudi 25 avril 2019

Performing Laravel Validation without $request

I am trying to perform validation without passing the $request variable, would someone be able to provide what I pass through the validator function? My code is below

public function change($id)
    {
        $user = User::find($id);

        $user->name = request("name");

        $user->date_of_birth = request("date");

        $user->email = request("email");

        $user->phone = request("phone");

        $user->address = request("address");

        $user->city = request("city");

        $user->postcode = request("postcode");

        $validator = Validator::make(request(), [
            'name' => 'required',
            'email' => 'email|string|max:255|unique:users',
            'phone' => 'required|numeric',
            'address' => 'required|numeric',
            'postcode' => 'required|numeric',
            'city' => 'required'
        ]);
        if ($validator->fails()) {
            return redirect("/user/edit")
                ->withErrors($validator)
                ->withInput();
        }
        $user->save();

        return redirect('/user');
    }

Again, i am trying this without $request

Any help would be appreciated!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire