Laravel Blade 爆炸 Html
Laravel Blade Explode Html
我有一个循环遍历我的多数组,但我需要使用 blade 语法对每个条目进行样式化。我试过用 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);
}
}
您的问题有两种可能。
1) 检查您的 blade 文件。它应该像 filename.blade.php
2) 你的阵列有问题。如果你的数组是 object 数组,你应该像 {{ $key->yourValue }}
那样打印出来。否则,{{ $key['yourValue'] }}
如果您提供阵列样本,我们可以为您的问题提供更好的答案。
希望对您有所帮助!我想就编码标准向您建议一件事。
根据PSR
标准,你应该遵循PSR
标准。我不建议像 $History
这样声明。它应该像 $history
。可以参考here
改成这个
@foreach($History as $Past)
<tr>
@foreach($Past as $key)
<td>{{$key}}</td>
@endforeach
</tr>
@endforeach
我有一个循环遍历我的多数组,但我需要使用 blade 语法对每个条目进行样式化。我试过用 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);
}
}
您的问题有两种可能。
1) 检查您的 blade 文件。它应该像 filename.blade.php
2) 你的阵列有问题。如果你的数组是 object 数组,你应该像 {{ $key->yourValue }}
那样打印出来。否则,{{ $key['yourValue'] }}
如果您提供阵列样本,我们可以为您的问题提供更好的答案。
希望对您有所帮助!我想就编码标准向您建议一件事。
根据PSR
标准,你应该遵循PSR
标准。我不建议像 $History
这样声明。它应该像 $history
。可以参考here
改成这个
@foreach($History as $Past)
<tr>
@foreach($Past as $key)
<td>{{$key}}</td>
@endforeach
</tr>
@endforeach