[英]Undefined '$qrcode' variable in blade laravel
I'm working on a Laravel project about how to generate a QR Code with a hashed information.我正在研究有关如何生成带有散列信息的 QR 码的 Laravel 项目。 However, when I call the variable from my blade file, it says 'Undefined variable $qrcode'.
但是,当我从刀片文件中调用该变量时,它会显示“未定义变量 $qrcode”。 May I get some help?
我可以得到一些帮助吗?
This is how my Controller (PostController) looks like:这就是我的 Controller (PostController) 的样子:
public function index()
{
$post = Post::all();
return view('blog.index', compact('post'));
}
public function create()
{
return view('blog.create');
}
public function store(Request $request)
{
$post = new Post;
$post->randomnumber = random_int(100000, 999999);
$post->user_id = Auth::id();
$post->unit = $request->input('unit');
$post->guestname = $request->input('guestname');
$post->guestphone = $request->input('guestphone');
$post->guestemail = $request->input('guestemail');
$post->guestic = $request->input('guestic');
$post->guestcarplate = $request->input('guestcarplate');
$post->numberofguests = $request->input('numberofguests');
$post->date = $request->input('date');
$post->time = $request->input('time');
$post->hash = Hash::make($post->randomnumber);
$post->save();
return view('blog.qrcode');
}
public function generate ($id)
{
$post = Post::findOrfail($id);
$qrcode = QrCode::size(300)->generate($post->hash);
return view('blog.qrcode', compact('qrcode'));
}
This is how my Route looks like:这就是我的路线的样子:
Route::get('posts/create', 'PostController@create')-
>middleware('auth');
Route::post('posts', 'PostController@store');
Route::get('/qrcode/{id}', function ($id) {
return redirect('blog.qrcode');
});
And this is how my blade file (qrcode.blade.php) looks like:这就是我的刀片文件 (qrcode.blade.php) 的样子:
@extends('layouts.frontend')
@section('content')
<h4>
QR Code
</h4>
{!! $qrcode !!}
@endsection
try this:尝试这个:
Route::get('/qrcode/{id}', 'PostController@generate');
instead of:代替:
Route::get('/qrcode/{id}', function ($id) {return redirect('blog.qrcode');});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.