4

I have created api with passport. My all api works fine on localhost. But when I deploy on shared hosting my login and register api is working fine but details api not working. I rewrite htacess rule but nothing happened. Why this problem occured?

Here is my sample code

Controller Class

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller; 
use App\User; 
use Illuminate\Support\Facades\Auth; 
use Validator;
class UserController extends Controller
{
 public $successStatus = 200;



 public function login(){ 
    if(Auth::attempt(['mobile' => request('mobile'), 'password' => request('password')])){ 
        $user = Auth::user(); 
        $success['token'] =  $user->createToken('quiz')-> accessToken; 
        return response()->json(['success' => $success], $this-> successStatus); 
    } 
    else{ 
        return response()->json(['error'=>'Unauthorised'], 401); 
    } 
}



 public function details() 
{ 
    $user = Auth::user()`enter code here`; 
    return response()->json(['success' => $user], $this-> successStatus); 
} 

}

Route

<?php

 use Illuminate\Http\Request;

 Route::post('register', 'UserController@register');

 Route::post('login', 'UserController@login');

 Route::group(['middleware' => 'auth:api'], function()
 {
 Route::post('details', 'UserController@details');
});


});

Model

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
use Notifiable;
use HasApiTokens;


protected $fillable = [
    'name', 'mobile', 'password','city','image',
];

protected $hidden = [
    'password', 'remember_token',
];



}

I get error InvalidArgumentException: Route [login] not defined.

Majid Alaeinia
  • 962
  • 2
  • 11
  • 27
Nokib
  • 51
  • 2

1 Answers1

0

Please make a change to the Apache config filr or .htaccess file with the below, hoping it will work:

RewriteEngine On RewriteCond %{HTTP:Authorization} ^(.+)$ RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

for Details visit: https://github.com/laravel/passport/issues/532