I'm trying to pass a token from middleware to view and controller. But all the steps I've tried:
- 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
Haven't helped much. Here is my setup:
Requests come in the form of:
https://website.com/reviews?linker=129b08e19014420049da7d6d7aa8fc35fc6279c4
Then gets parsed and checked by middleware:
Middleware
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);
}
}
}
}
** View **
<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>
When I go to get the session data within my view/controller, I get the error:
Undefined variable: data
Any ideas anyone?