Validate Is Not A Function In Laravel

Submitted by pakainfo - 4 years ago

As I will cover this Post with live Working example to develop laravel 5.8 get validation errors ajax, so the this.validate is not a function react native is used for this example is following below. https://www.pakainfo.com/validate-is-not-a-function-in-laravel/

https://www.pakainfo.com/validate-is-not-a-function-in-laravel/

<?php


namespace App\Http\Controllers;


use Illuminate\Http\Request;
use Validator;


class MemberController extends Controller
{


    /**
     * Display a listing of the lovemember.
     *
     * @return \Illuminate\Http\Response
     */
    public function lovemember()
    {
    	return view('lovemember');
    }


    /**
     * Display a listing of the lovememberPost.
     *
     * @return \Illuminate\Http\Response
     */
    public function lovememberPost(Request $request)
    {


    	$validator = Validator::make($request->all(), [
            'member_user_name' => 'required',
            'member_sir_name' => 'required',
            'email' => 'required|email',
            'locations' => 'required',
        ]);


        if ($validator->passes()) {


			return response()->json(['success'=>'Added new records.']);
        }


    	return response()->json(['error'=>$validator->errors()->all()]);
    }
}