我在laravel应用中创建了pdf创建者链接。但是,当我单击指向PDF的链接时,我得到了404。这是我的代码:
链接到客户:
<a href="/mvs/mvs/public/admin/kunden/pdf/{{ $kunden->id }}">Button html</a>
路线:
Route::get('/mvs/mvs/public/admin/kunden/pdf/{id}', 'DynamicPDFController@get_customer_data');
PDF控制器:
use Illuminate\Http\Request;
use DB;
use PDF;
class DynamicPDFController extends Controller
{
function index()
{
$customer_data = $this->get_customer_data();
$finance_data = $this->get_finance_data();
return view('dynamic_pdf')->with('customer_data', $customer_data);
}
function get_customer_data($id)
{
//Handle PDF stuff here
$customer_data = DB::table('kundens')
->where('id', '=', $id)
->firstOrFail();
//Save PDF link to customer here
$customer_data->save();
return $customer_data;
}
function pdf()
{
$pdf = \App::make('dompdf.wrapper');
$pdf->loadHTML($this->convert_customer_data_to_html());
return $pdf->stream();
}
function convert_customer_data_to_html()
{
$customer_data = $this->get_customer_data();
$output = '
<h3 align="center">Angebot</h3>
<table width="100%" style="border-collapse: collapse; border: 0px;">
<tr>
<th style="border: 1px solid; padding:12px;" width="20%">Vorname</th>
<th style="border: 1px solid; padding:12px;" width="30%">Nachname</th>
<th style="border: 1px solid; padding:12px;" width="15%">Stadt</th>
<th style="border: 1px solid; padding:12px;" width="15%">PLZ</th>
';
foreach($ customer_data为$ kunden)
{
$ output。='
'。$ kunden-> vorname。
'。$ kunden-> nachname。
'。$ kunden-> wohnort。'
'。$ kunden-> plz。
完整路线:
Route::get('/mvs/mvs/public/admin/kunden/pdf/{id}',
'DynamicPDFController@get_customer_data');
Route::get('/home', 'HomeController@index')->name('home');
Route::resource('admin/kunden', 'KundenController');
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Route::get('/dynamic_pdf', 'DynamicPDFController@index');
Route::get('/dynamic_pdf/pdf', 'DynamicPDFController@pdf');
当我现在单击链接“ Button HTML”时,出现404错误页面。但是我不知道为什么:(
更新:
Call to undefined method stdClass::save()
那是新的错误-我编辑了答案的路线。
答案 0 :(得分:1)
尝试将您的路线更改为此:
Route::get('/admin/kunden/pdf/{id}', 'DynamicPDFController@get_customer_data');
(与您的其他路线相同)
我认为您的index.php文件位于/mvs/mvs/public/
,因此Laravel只会从那里获取路由。