Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

signup API in laravel

/**
 * API Register
 *
 * @param Request $request
 * @return IlluminateHttpJsonResponse
 */
public function register(Request $request)
{
    $rules = [
        'name' => 'unique:users|required',
        'email'    => 'unique:users|required',
        'password' => 'required',
    ];

    $input     = $request->only('name', 'email','password');
    $validator = Validator::make($input, $rules);

    if ($validator->fails()) {
        return response()->json(['success' => false, 'error' => $validator->messages()]);
    }
    $name = $request->name;
    $email    = $request->email;
    $password = $request->password;
    $user     = User::create(['name' => $name, 'email' => $email, 'password' => Hash::make($password)]);

}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #signup #API #laravel
ADD COMMENT
Topic
Name
3+6 =