PDF сгенерирован, но он только что скачан, а не открыт на вкладке.
Я хочу открыть случайно сгенерированную страницу PDF в браузере, откуда пользователь может ее скачать.
Я попытался создать PDFкод? Это мой контроллер.
Пожалуйста, предложите некоторый код здесь в функции show.
<?php
namespace App\Http\Controllers;
use App\Item;
use DB;
use Excel;
use PDF;
use Illuminate\Http\Request;
//use App\Mail\DemoEmail;
use Illuminate\Support\Facades\Mail;
class MaatwebsiteDemoController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function importExport()
{
return view('importExport');
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function downloadExcel($type)
{
$data = Item::get()->toArray();
return Excel::create('itsolutionstuff_example', function ($excel) use ($data) {
$excel->sheet('mySheet', function ($sheet) use ($data) {
$sheet->fromArray($data);
});
})->download($type);
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function importExcel(Request $request)
{
$request->validate([
'import_file' => 'required'
]);
$path = $request->file('import_file')->getRealPath();
$data = Excel::load($path)->get();
//echo "<pre>";
//print_r($data);exit;
if ($data->count()) {
foreach ($data as $key => $value) {
foreach ($value as $key1 => $x1) {
$arr[] = ['email' => $x1->email, 'description' => $x1->description, 'content' => $x1->content];
}
}
if (!empty($arr)) {
Item::insert($arr);
}
//$data1 = Item::get()->toArray();
$users = Item::get()->toArray();
foreach ($users as $keycc => $user) {
$data2[] = $user['email'];
Mail::send('mails.demo', $user, function ($message) use ($user) {
$message->to($user['email'], 'Tutorials Point')->subject('Laravel HTML Testing Mail');
$message->from('smitamishra1992718@gmail.com', 'Smita');
});
}
// Mail::send('emails.contact', $data, function($message) use ($data){
// return back()->with('success', 'Insert Record successfully.');
}
}
//Here i am loading view as pdf bt it not open in a new tab as pdf it just dowloaded.
public function show($id)
{
$users = DB::select('select * from items where id = ?', [$id]);
//view()->share('users',$users);
$pdf = PDF::loadView('pdfview', array('users' => $users));
return $pdf->download('demo.pdf');
}
public function downloadPDF()
{
$pdf = PDF::loadView('pdfview');
return $pdf->download('invoice.pdf');
}
}
Это мой взгляд, имеющий ссылку. Когда мы нажимаем на эту страницу ссылки, открываем ее как pdf в браузере.
<a href="{{ route('pdfview', $id) }}">Content Detail Displayed here</a>