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 –