0
我已經爲API創建了我自己的中間件。以下是我爲獲得基於該請求有效的用戶信息碼PARAMS access_token
如何從中間件獲取變量?
namespace App\Http\Middleware;
use Closure;
use App\Exceptions\GeneralException;
use App\Models\Access\User\User;
class authNS
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
try {
$user = User::where("access_token",$request->header('access-token'))->with('details')->first();
} catch (Exception $e) {
return response()->json(['error'=>'Something is wrong']);
}
return $next($request);
}
}
但如何將我的Controller
內訪問此$user
變量?
太謝謝你了。它工作完美 – devmyb
@iCode,我需要你的幫助。看看這裏:http://stackoverflow.com/questions/41030097/how-to-add-some-textfield-in-form-register-laravel-generator-infyom –