Hello, I have a problem and I found a part of the solution here, I'm dealing with this in a different way in another question, however I decided to test a form I saw here from the user Vigilio about DomPDF My case is as follows, I have course and students, I need to return all students enrolled in a PDF course, I can return normally, but when I try to return in pdf it says that an argument is missing, follow the codes
PdfviewController.php
<?php namespace App\Http\Controllers;
use App\Curso;
use App\Aluno;
use Barryvdh\DomPDF\Facade as PDF;
class PdfviewController extends Controller
{
private $model;
public function __construct(Curso $model)
{
$this->model = $model;
}
public function index($id)
{
$data['model'] = $this->model->findOrFail($id);
$alunos = $curso->alunos;
return PDF::loadView('viewpdf.index', $data, $alunos)->stream();
}
}
Route
Route::get('/viewpdf', 'PdfviewController@index');
index.blade.php
<!DOCTYPE html>
<html lang="{{ config('app.locale') }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">
</head>
<body>
<div class="flex-center position-ref full-height">
<table>
<thead>
<tr>
<th>Id</th>
<th>Curso</th>
</tr>
</thead>
<tbody>
@foreach($alunos as $item)
<tr>
<td>{{$item->id}}</td>
<td>{{$item->nome}}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</body>
</html>
I'm wondering if I should pass the ID on the route in this case, but every time I try the result is the same
(1/1) ErrorException Missing argument 1 for App \ Http \ Controllers \ PdfviewController :: index ()