Php 如何处理刀片拉威尔
我的控制器功能是。我通过数组传递了数据,但数组数据无法打印 这是我的刀片在这个刀片我的数据打印从数据库。 如何打印阵列?刀片中阵列打印的索引Php 如何处理刀片拉威尔,php,laravel,Php,Laravel,我的控制器功能是。我通过数组传递了数据,但数组数据无法打印 这是我的刀片在这个刀片我的数据打印从数据库。 如何打印阵列?刀片中阵列打印的索引 @php dd(投标人); $index=0; @endphp @foreach(投标人为$bid) @foreach($posts作为$post) @如果($post->id==$bid[$index]['post\u id'])) 你的帖子标题:{{$bid[$index]>Post->Title} @如果($bid[$index]->Tutor-
@php
dd(投标人);
$index=0;
@endphp
@foreach(投标人为$bid)
@foreach($posts作为$post)
@如果($post->id==$bid[$index]['post\u id']))
你的帖子标题:{{$bid[$index]>Post->Title}
-
@如果($bid[$index]->Tutor->profile\u Image=='')
@否则
{--{{asset('storage/app/public/profileImages/'.$pic->profile_Image)}--}
@恩迪夫
主题:
@foreach($bid[$index]->Tutor->subject作为$sub)
{{\App\Models\Subject::find($sub->pivot->Subject\u id)->Subject}}
@endforeach
- PKR:{{{$bid[$index]>bid\u price}}固定价格
- 天数:{{$bid[$index]->Days}交付时间
{{--@dd($bid->id)--}
我认为您只需要重构代码即可,
首先,使用$bid->{$index}而不是这个$bid[$index]。您有集合,但可以将其用作数组
您想按post_id对投标人进行分组吗 你应该使用关系,
如果要显示投标人列表,请在投标人模型中
app/bidders.php
假设您在表结构中有适当的标准来映射雄辩
然后你需要改变你的投标人功能如下
public function bidders()
{
$payments = \App\Models\Payment::get();
$bidders = Bidder::whereHas('post', function($post) {
return $post->where('user_id','=',Auth::user()->id);
//Provides a filter for bidders, post which are related to user
})->with('post')->get();
return view('user.student.student-post-bidders',compact('bidders', 'payments'));
}
在刀片上应该只有一个回路供投标人使用,如下所示
以下是您的答案,说明为什么json_encode的刀片签入注释中没有出现数组
@foreach($bidders as $bid)
{{$bid->id}} //gives you bid parameters
{{json_encode($bid->post)}} //this will get all the post details array/object is not printable on blade so encoded to json just for display purpose
//suppose you need only name from post then
{{$bid->post->name}};
@endforeach
这将降低您的代码长度,并由于快速加载和较少循环而提高性能。还删除了创建数组、维护索引和检查刀片上id的if条件等内容
就这样。
快乐编码 在First foreach中尝试一个{{dd($bid)}
。为什么不尝试使用雄辩的关系呢?
public function post()
{
return $this->belongsTo('App\Post');
}
public function bidders()
{
$payments = \App\Models\Payment::get();
$bidders = Bidder::whereHas('post', function($post) {
return $post->where('user_id','=',Auth::user()->id);
//Provides a filter for bidders, post which are related to user
})->with('post')->get();
return view('user.student.student-post-bidders',compact('bidders', 'payments'));
}
@foreach($bidders as $bid)
{{$bid->id}} //gives you bid parameters
{{json_encode($bid->post)}} //this will get all the post details array/object is not printable on blade so encoded to json just for display purpose
//suppose you need only name from post then
{{$bid->post->name}};
@endforeach