将 id 变量传递给“where”请求,以获取与 id 匹配的数据库条目,并使用 Laravel Excel 将这些条目导出到 Excel 表。我似乎找不到传递变量的方法。
我的控制器:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Exports\MttRegistrationsExport;
use Maatwebsite\Excel\Facades\Excel;
class ExcelController extends Controller
{
public function export($id)
{
return Excel::download(new MttRegistrationsExport, 'MttRegistrations.xlsx', compact('id'));
}
}
Run Code Online (Sandbox Code Playgroud)
我的导出文件:
<?php
namespace App\Exports;
use App\MttRegistration;
use Maatwebsite\Excel\Concerns\FromCollection;
class MttRegistrationsExport implements FromCollection
{
/**
* @return \Illuminate\Support\Collection
*/
public function collection()
{
return MttRegistration::where('lifeskill_id',$id)->get()([
'first_name', 'email'
]);
}
}
Run Code Online (Sandbox Code Playgroud)
我的路线:
Route::get('/mtt/attendance/{id}',[
'as' => 'mtt.attendance',
'uses' => 'ExcelController@export']);
Run Code Online (Sandbox Code Playgroud) 我目前正在使用 Google 2fa 的包,并从控制器中以字符串变量的形式提取 SVG QR 代码,然后根据包的要求将 QR 代码添加为 . 问题是这不显示图像,我认为这是由于我从控制器中提取的字符串值造成的。
这是我从控制器收到的变量值:
当在我的刀片文件中回显此内容时,它只是回显字符串值。如果我要复制这个不带“”的字符串值,Laravel 会将该值识别为 html 并显示我的二维码。有没有办法回显刀片将其识别为html代码?或者,当我以这种方式将其作为变量拉入时,如何在我的 Blade 文件中显示此 SVG 文件?如果有人愿意帮助我,我将不胜感激!
链接到 Laravel 包 -> https://github.com/antonioribeiro/google2fa-laravel
我的控制器:
public function register(Request $request)
{
//Validate the incoming request using the already included validator method
$this->validator($request->all())->validate();
// Initialise the 2FA class
$google2fa = app('pragmarx.google2fa');
// Save the registration data in an array
$registration_data = $request->all();
// Add the secret key to the registration data
$registration_data["google2fa_secret"] = $google2fa->generateSecretKey();
// Save the registration data to the …Run Code Online (Sandbox Code Playgroud)