2017-02-20 3 views
2

Ich lerne Laravel und stieß auf diesen Fehler.Laravel 5.4 (mit JWT) - NotFoundHttpException in RouteCollection.php Zeile 161

NotFoundHttpException in RouteCollection.php Linie 161:

Ja Ich suche bereits Lösungen aus dem Internet, aber keiner von ihnen fixiert mein Problem ich andere Wege im selben Projekt haben, die arbeiten, nur Diese Authentifizierungsroute funktioniert nicht.

AuthenticateController.php

<?php 

namespace App\Http\Controllers; 

use Illuminate\Http\Request; 
use App\Http\Requests; 
use App\User; 
use JWTAuth; 
use App\Http\Controllers\Controller; 
use Tymon\JWTAuth\Exceptions\JWTException; 

class AuthenticateController extends Controller{ 

public function __construct(){ 
    $this->middleware('jwt.auth',['except'=>['authenticate']]); 
} 

public function index(){ 
    return "Auth index"; 
} 

public function authenticate(Request $request){ 
    $credentials =$request->only('phonenumber','generatednexmotoken'); 
    try{ 
     //verify the credentials and create a token for the user_error 
     if($token=JWTAuth::attempt($credentials)){ 
      return response()->json(['error'=>'invalid_credentials']); 
     }else{ 
      return response()->json(compact('token')); 
     } 
    }catch(Tymon\JWTAuth\Exceptions\JWTException $e){ 
     return response()->json(['error'=>'could not create toke']); 
    } 
} 

public function getAuthenticatedUser(){ 
    try{ 
     if(! $user = JWTAuth::parseToken()->authenticate()){ 
      return responnse()->json(['user not found',404]); 
     }else{ 
      return response()->json(compact('user')); 
     } 
    }catch(Tymon\JWTAuth\Exceptions\TokenExpiredException $e){ 
     return response()->json(['token expired'],$e->getStatusCode()); 
    }catch(Tymon\JWTAuth\Exceptions\TokenInvalidExceptions $e){ 
     return response()->json(['invalid token'],$e->getStatusCode()); 
    }catch(Tymon\JWTAuth\Exceptions\JWTException $e){ 
     return response()->json(['token is absent lol'],$e- 
     >getStatusCode());   
    } 
} 
} 

User.php

<?php 

namespace App; 

use Illuminate\Notifications\Notifiable; 
use Illuminate\Foundation\Auth\User as Authenticatable; 

class User extends Authenticatable 
{ 
use Notifiable; 

/** 
* The attributes that are mass assignable. 
* 
* @var array 
*/ 
protected $fillable = [ 
    'phonenumber', 'generatednexmotoken', 
]; 

/** 
* The attributes that should be hidden for arrays. 
* 
* @var array 
*/ 
protected $hidden = [ 
    'generatednexmotoken', 'jwttoken', 
]; 
} 

api.php

Route::group(['prefix' => 'v1'], function() 
{ 
Route::post('authenticate', '[email protected]'); 
Route::get('authenticate/user', 
'[email protected]');   
}); 

Route::get('/sms/send/{to}', function(\Nexmo\Client $nexmo, $to){ 
$message = $nexmo->message()->send([ 
    'to' => $to, 
    'from' => '@leggetter', 
    'text' => 'Sending SMS from Laravel. Woohoo!' 
]); 
    Log::info('sent message: ' . $message['message-id']); 
}); 

Hinweis:

  1. Ich bin nur meinem lokalen Rechner mit (php Handwerker dienen)

  2. api/sms/Senden/{to} funktioniert.

  3. Aber wenn ich auf api/v1/authenticate zugreifen werde, wird es eine NotFoundHttpException in RouteCollection.php Linie 161 Fehler werfen.

Danke

+0

Was meinst du mit Zugriff api/v1/authenticate? Eine Post-Anfrage oder eine Anfrage bekommen? – piscator

+1

@piscator Ich habe es per POST in POSTMAN Zugriff auf den gesamten Link und es ist alles meine Schuld ich falsch geschrieben authentifizieren zu authentifizieren Vielen Dank für Ihre Antwort. – iamj

Antwort

1

Wie Sie api/v1/authenticate zugreifen.? (Browser oder sonst wie Postbote oder Frontend). Ihr Code scheint korrekt, aber die Wahrscheinlichkeit eines Fehlers ist, wenn Sie versuchen, auf api/v1/authenticate API über GET Methode zuzugreifen. Können Sie angeben, wie Sie darauf zugreifen?

+0

Vielen Dank für den Hinweis auf @Vaibhavraj Ich schrieb mein authenticate zu athenticate falsch, als ich meinen Briefträger überprüfte: D – iamj

+0

Froh, dass es funktioniert: –

Verwandte Themen