【发布时间】:2018-06-08 07:10:20
【问题描述】:
我正在更新 laravel 刀片模板以将一些数据库信息插入到 html 表中。为此,我必须将新数据添加到此刀片的控制器中,这就是我遇到问题的地方。
我仍在尝试通过 laravel 了解更多信息,因此我认为我创建此数据的语法或方法不正确,但我现在无法确定。
在我下面的函数中,$calls_allowed 部分已经存在并且它当前在页面上工作。我创建了函数的 $contact_events 部分,这就是我的问题所在。
在我看来,我围绕有问题的 html 表创建了一个 foreach 循环和 if 语句。该表已加载,但即使数据库中有经销商的记录,它也是空的。
我想说
if $dealer-> id matches contact_events.dealer_num, load all records for that dealer
contact_events 是表,dealer_num 是我要匹配的列,然后我尝试将该表中的列 (updated_at,method,notes) 加载到 html 表中.
受影响的代码如下。视图/路由/控制器工作,只是我正在创建的这个函数没有加载数据。非常感谢任何帮助。
控制器代码:
public function show($id)
{
$d = Dealer::find($id);
if(!$d){
\Session::flash('warning_message', 'Sorry that resource can not be found.');
return redirect()->route('account.dealer.index');
}
$calls_allowed = DB::table('dealers.dealers')->
where('dealer_num', $id)->
pluck('calls_allowed');
$contact_events = DB::table('dealers.contact_events')->
where('dealer_num', $id)->
pluck('updated_at', 'method', 'notes');
if(!empty($calls_allowed)){
$d->calls_allowed = $calls_allowed[0];
} else {
$d->calls_allowed = null;
}
return view('Account.Dealer.show')->with('dealer', $d);
}
查看代码:
<thead>
<tr>
<th>Contacted Date</th>
<th>Type of Contact</th>
<th>Call Notes</th>
</tr>
</thead>
@foreach($dealer->contact_events as $events)
@if($events->dealer_num = $dealer->id)
<tbody>
<tr>
<td>{{$events->updated_at}}</td>
<td>{{$events->method}}</td>
<td>{{$events->notes}}</td>
</tr>
</tbody>
@endif
@endForeach
【问题讨论】:
-
这里有一个类型:@if($events->dealer_num = $dealer->id) 应该是==
-
我确实发现了,但不幸的是它仍然没有解决问题
-
使用 dd() 查看 $calls_allowed 和 $contact_events 是否正在获取值
-
dealers.dealers 和deals.contact_events 列在dealer 表上吗?
-
@retrograde 经销商是模式的名称。 Contact_events 和 Dealers 都是该架构中的一个表