0

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"
    }
  ]
}
6
  • What is the output of dd($orders); Commented Feb 19, 2021 at 12:44
  • @user15070659 I updated the question with the output now Commented Feb 19, 2021 at 12:52
  • show to us the database schema for table order , category, and reverse relationship that you use ? Commented Feb 19, 2021 at 13:16
  • You can explode $order-> categoria on the ", " char, so it becomes an array. Commented Feb 19, 2021 at 13:37
  • @GertB. Yes, but how would I pass it to the view and display? Commented Feb 19, 2021 at 14:59

1 Answer 1

1
@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 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.