में उपयोगकर्ता भूमिका जोड़ें मेरे पास एक लार्वेल 5 बैकएंड है जो jwt-auth के साथ लॉगिन पर एक जेसन प्रतिक्रिया के रूप में एक jwt-टोकन भेजता है।jwt, laravel 5 jwt-auth
यह मेरे वर्तमान नियंत्रक
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use JWTAuth;
use Tymon\JWTAuth\Exceptions\JWTException;
use Illuminate\Database\Eloquent\Model;
use App\User;
class AuthenticateController extends Controller
{
public function authenticate(Request $request)
{
// grab credentials from the request
$credentials = $request->only('email', 'password');
$user = User::where('email', '=', $credentials['email'])->first();
$customClaims = ['role' => $user->role];
try {
// attempt to verify the credentials and create a token for the user
if (! $token = JWTAuth::attempt($credentials, $customClaims)) {
return response()->json(['error' => 'invalid_credentials'], 401);
}
} catch (JWTException $e) {
// something went wrong whilst attempting to encode the token
return response()->json(['error' => 'could_not_create_token'], 500);
}
// all good so return the token
return response()->json(compact('token'));
}
}
?>
है वहाँ एक क्लीनर तरीका है:
अब मैं जेडब्ल्यूटी टोकन laravel भेजता है करने के लिए उपयोगकर्ता भूमिका जोड़ना चाहते हैं, मैं निम्नलिखित तरीके से करने की कोशिश की यह करने के लिए ?
PHP के लिए जेडब्ल्यूटी खराब दस्तावेज है। एक साधारण लॉगिन/लॉगआउट सिस्टम बनाने के लिए दर्दनाक है! इसके बारे में मेरे प्रश्न देखें। – Maykonn
मैं वही चीज़ ढूंढ रहा था, क्या आपको कोई समाधान मिला? – kitensei
मैं ऊपर दिए गए समाधान के साथ गया, भले ही यह एक और सवाल है। एक क्लीनर समाधान – RVandersteen