Ad

Laravel Blade Explode Html

- 1 answer

I have a loop that literates through my multi array but I need each entry to by styled using the blade syntax. I've tried echoing out the Html with php but that didn't work.

This is what I'm trying to do in a Blade syntax

 echo '<td>'.$key.'</td>';

Array

    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"
  }
]

View

      <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>

Controller

<?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);
    }
}
Ad

Answer

There are two possible things for your question.

1) Check your blade file. It's should be like filename.blade.php

2) Your array have some problem. If your array is object array, you should print out like that {{ $key->yourValue }}. Otherwise, {{ $key['yourValue'] }}

If you provide your array sample, we can provide better answer for your question.

Hope this help! I want to suggest you one thing for coding standard.

According to PSR standard, you should follow PSR standard. I'm not recommend to declare like $History. It's should be like $history. You can reference from here

Change to this

 @foreach($History as $Past)
      <tr>
          @foreach($Past as $key)
              <td>{{$key}}</td>
          @endforeach
      </tr>
 @endforeach
Ad
source: stackoverflow.com
Ad