我有一个通过我的多数组识别的循环,但我需要使用刀片语法设置每个条目。我试过用PHP回显Html,但是没有用。
这就是我在Blade语法中尝试做的事情
echo '<td>'.$key.'</td>';
阵列
array:2 [▼
0 => {#173 ▼
+"Name": "Rama Berger"
+"StockName": "apple"
+"price": 100
+"Date": "2016-01-07 17:31:06"
}
1 => {#172 ▼
+"Name": "Rama Berger"
+"StockName": "apple"
+"price": 11
+"Date": "2016-01-07 20:00:38"
}
]
查看
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>Name</th>
<th>Stock</th>
<th>Order Amount</th>
<th>Date</th><br>
</tr>
</thead>
<tbody>
@foreach($History as $Past)
@foreach($Past as $key)
<tr>
<td>{{$key}}</td>
</tr>
@endforeach
@endforeach
</tbody>
</table>
控制器
<?php
namespace App\Http\Controllers;
use \View as View;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Request;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class RequestController extends BaseController
{
public function GetHistory(){
$name = Auth::user()->name;
$History = DB::table('History')->select('Name', 'StockName', 'price', 'Date')->where('StockName', '=', 'apple')->get();
return view('pages.home')->with('History', $History);
}
}
答案 0 :(得分:0)
您的问题有两种可能的问题。
1)检查刀片文件。它应该像filename.blade.php
2)你的阵列有问题。如果您的数组是对象数组,则应该像{{ $key->yourValue }}
那样打印出来。否则,{{ $key['yourValue'] }}
如果您提供阵列样本,我们可以为您的问题提供更好的答案。
希望这有帮助!我想建议你编码标准的一件事。
根据PSR
标准,您应遵循PSR
标准。我不建议像$History
那样声明。它应该像$history
一样。您可以参考here
更改为
@foreach($History as $Past)
<tr>
@foreach($Past as $key)
<td>{{$key}}</td>
@endforeach
</tr>
@endforeach