Nayana
Nayana

Reputation: 147

Get single column array in database and display in laravel blade

I'm trying to display values separately from a specific column "category" from my database table "order" which is an array with values like "value1,value2,value3".

I want to get those values and display them separately in laravel blade. Something like $order->category[1]. I can't figure out how I can do it because I still want to display all values from other columns at the same time.

Here's my controller:

 public function index()
    
    { $orders =  DB::table('order')
        ->where('email', auth()->user()->email)
        ->get();


    return view('dashboard', [
        'orders' => $orders,
       
    ]);
       
    }

And here's my blade:

 @foreach ($orders->reverse() as $key => $order )
   <div class="layout__primary"> 
     <div class="works header-item2">
      <div class="item-text2">{{ $order->name }}</div>
        <img src="{{ $order->category[1] }}" class="works-img" style="max-width: 280px">
          <div class="item-labels">{{ $order->category[2] }}</div>
                  </div>
                </div>
               @endforeach 

And dd($order)

Illuminate\Support\Collection {#1374 ▼
  #items: array:1 [▼
    0 => {#1386 ▼
      +"id": 50
      +"name": "Name"
      +"email": "[email protected]"
      +"mobile": 12348890
      +"category": "Personal,assets/img/personal.png,Personal Website"
      +"contact": "email"
      +"domain": null
      +"new_domain": null
      +"alojamento": null
      +"criar_email": null
      +"facebook": null
      +"instagram": null
      +"linkedin": null
      +"plan": null
      +"order_date": "2021-02-19 12:06:48"
      +"state": "Processing"
    }
  ]
}

Upvotes: 0

Views: 1285

Answers (1)

msbomrel
msbomrel

Reputation: 519

@foreach ($orders->reverse() as $key => $order )
       <div class="layout__primary"> 
         <div class="works header-item2">
          <div class="item-text2">{{ $order->name }}</div>
            <img src="{{ explode(",", $order->category)[1] }}" class="works-img" style="max-width: 280px">
              <div class="item-labels">{{ $order->category[2] }}</div>
                      </div>
                    </div>
                   @endforeach 

Upvotes: 1

Related Questions