0
    public function register(Request $request) {
//        $user = User::create([
//            'name' => $request->input('name'),
//            'email' => $request->input('email'),
//            'password' => Hash::make($request->input('password'))
//        ]);
//
//        return $user;

        return "test";
    }

Hi all, basically, I'm trying to build a restful API with Laravel and my API is being hit by Postman, but when I send a JSON body my $request is an empty array.

It's the first time I'm touching Laravel so it's probably something obvious so thank you in advance !

1

1 Answer 1

0

Try this one

use Exception;

  public function register(Request $request) {
       

 try {
          $user = User::create([
          'name' => $request->input('name'),
          'email' => $request->input('email'),
          'password' => Hash::make($request->input('password'))
        ]);
    
       return response()->json(['status' => true, 'message' => 'You have been register successfully', 'data' => $user]);
        } catch (Exception $e) {
            return response()->json(['status' => false, 'message' => $e->getMessage(), 'data' => []]);
        }
        
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.