2
votes

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.
2
show ur postman request - Jignesh Joisar
Are you running your api with php artisan or inside apache? Usually when you run php artisan serve it is hosted in default port of 8000. So you need to use port number in postman. - InvincibleElf
i am directly making the post request in postman - Nandan
@Nandan try the URL with the protocol http://localhost/mywebsite/api/signup - N69S

2 Answers

8
votes

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

0
votes

Your code is correct. It seems like you are missing public from url

localhost/my_webiste/public/api/signup