Laravel 5路由错误
问题描述:
我对laravel 5.4很陌生,所以我需要在一个视图中调用这两个函数。 这里是2个控制器。Laravel 5路由错误
public function index()
{
$items = trainingprogramedetails::all()->last();
return view('programesession/index',compact('items'));
}
public function list()
{
$lists = trainingprogramedetails::all();
return view('programesession/index',compact('lists'));
}
这是我的看法index.blade.php
<thead>
<th>Name</th>
<th>Data</th>
</thead>
<tbody>
<tr>
<td>Date</td>
<td>{{ $items->date_of_programe }}</td>
</tr>
<tr>
<td>Time</td>
<td>{{ $items->time }}</td>
</tr>
<tr>
<td>Venue</td>
<td>{{ $items->venue }}</td>
</tr>
</tbody>
</table>
<table class="table table-striped">
<thead>
<th>Trainee Programe ID</th>
<th>Presenter Name</th>
<th>Division</th>
<th>Date</th>
</thead>
<tbody>
@foreach($lists as $item)
<tr>
<td>{{ $item->training_programe_id }}</td>
<td>{{ $item->presenter_name }}</td>
<td>{{ $item->division }}</td>
<td>{{ $item->date }}</td>
</tr>
@endforeach
</tbody>
</table>
这里是我的溃败
Route::group(['middleware' => ['web']], function() {
Route::resource('/programelist', 'TrainingProgrameSeassion');
});
你能帮忙解决这个问题吗?
答
正如问题所述,我知道你在调用索引路由时可能会调用index()
函数,而不是list()
函数。
这个问题不是很清楚,需要进一步澄清。
您需要在单个函数中使用这两个变量才能实现解决方案。
public function index()
{
$items = trainingprogramedetails::all()->last();
$lists = trainingprogramedetails::all();
return view('programesession/index', compact('items', 'lists'));
}
这个错误是因为你要么调用索引方法或列表的方法,而不是两个,并通过只items
视图变量和lists
变量不存在造成的。
如果答案不是您想要的,请添加更多代码并详细说明您的问题。
答
我认为你需要更新你的观点一样:
@if(isset($items))
<table>
<thead>
<th>Name</th>
<th>Data</th>
</thead>
<tbody>
<tr>
<td>Date</td>
<td>{{ $items->date_of_programe }}</td>
</tr>
<tr>
<td>Time</td>
<td>{{ $items->time }}</td>
</tr>
<tr>
<td>Venue</td>
<td>{{ $items->venue }}</td>
</tr>
</tbody>
</table>
@endif
@if(isset($lists))
<table class="table table-striped">
<thead>
<th>Trainee Programe ID</th>
<th>Presenter Name</th>
<th>Division</th>
<th>Date</th>
</thead>
<tbody>
@foreach($lists as $item)
<tr>
<td>{{ $item->training_programe_id }}</td>
<td>{{ $item->presenter_name }}</td>
<td>{{ $item->division }}</td>
<td>{{ $item->date }}</td>
</tr>
@endforeach
</tbody>
</table>
@endif
希望这对你的工作。
答
任何不合并这两个功能的理由?另一种解决方案应该处理当前的错误。如果确实需要两个功能,它可能是最好使用谐音以及
public function index()
{
$items = trainingprogramedetails::all()->last();
$lists = trainingprogramedetails::all();
return view('programesession/index',compact('lists','items'));
}
答
你应该使用这样正确的代码
为什么你认为它是与路线的问题吗?你甚至读过错误信息吗? – Amarnasan
我是新来的laravel.whatever这是我的大学生项目的情况下,我必须使用laravel.i认为这是路由问题。如果我知道它,我不会问它作为一个问题 – Dasun