Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel API routes not working with Postman

Tags:

laravel

My route/api.php has these routes:

Route::post('/signup' , 'UserApiController@signup');
Route::post('/logout' , 'UserApiController@logout');
Route::post('/verify' , 'UserApiController@verify');

but when I'm trying to access from Postman like this, it shows object not found:

localhost/my_webiste/api/signup

here the userapicontroller signup function:

public function signup(Request $request)
{
    $this->validate($request, [
            'social_unique_id' => ['required_if:login_by,facebook,google','unique:users'],
            'device_type' => 'required|in:android,ios',
            'device_token' => 'required',
            'device_id' => 'required',
            'login_by' => 'required|in:manual,facebook,google',
            'first_name' => 'required|max:255',
            'last_name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'mobile' => 'required',
            'password' => 'required|min:6',
        ]);

    try{

        $User = $request->all();

        $User['payment_mode'] = 'CASH';
        $User['password'] = bcrypt($request->password);
        $User = User::create($User);

        return $User;
    } catch (Exception $e) {
         return response()->json(['error' => trans('api.something_went_wrong')], 500);
    }
}

here the postman output of post request of localhost/mywebsite/api/signup :

    <title>Object not found!</title>
    <link rev="made" href="mailto:postmaster@localhost" />
   <h1>Object not found!</h1>
   The requested URL was not found on this server.
   If you entered the URL manually please check your
spelling and try again.
like image 790
Nandan Avatar asked Sep 19 '25 15:09

Nandan


1 Answers

Make sure, in your postman, to add the header accept = application/json.

like image 67
N69S Avatar answered Sep 22 '25 10:09

N69S