【发布时间】:2017-06-14 03:17:43
【问题描述】:
我正在尝试将令牌从中间件传递给视图和控制器。但是我尝试过的所有步骤:
- Laravel - Passing variables from Middleware to controller/route
- Pass variable from middleware to templates
- Pass variable from middleware to view via controller in Laravel 5.2
帮助不大。这是我的设置:
请求的形式为:
https://website.com/reviews?linker=129b08e19014420049da7d6d7aa8fc35fc6279c4
然后被中间件解析和检查:
中间件
class CheckReviewLink
{
/**
* Check Review Link - granting clients access to submit review
* =================
* Check that user's link matches the 40 character string generated for user
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$response = $next($request);
$url = $_SERVER['REQUEST_URI'];
$parts = parse_url($url);
$data['token'] = parse_str($parts['query'], $query);
$testimonies = Testimony::all();
foreach ($testimonies as $testimony) {
if ($query['linker'] == $testimony->token) {
Session::flash('token', $data);
return $next($request);
}
}
}
}
** 查看 **
<div class="col-lg-6">
<article>
<input disabled type="text" placeholder="{{Session::get('token', $data)}}" id="token" name="token" size="100" class="form-control border-form white font4light">
</article>
</div>
当我在视图/控制器中获取会话数据时,出现错误:
Undefined variable: data
有什么想法吗?
【问题讨论】: