0

Hi I have the following query:

$inc_quotes = DB::table('inc_quotes')->where('session_id', '=', $session_id)->get();

And it returns an array of arrays I believe like below:

    array:36 [▼
  0 => {#232 ▼
    +"id": "5"
    +"session_id": "1ee0556134d377c05673fce16f719b3e1077c797"
    +"brand": "Acer"
    +"drive": "Full Size Laptop"
    +"screen": "Less than 2 Years old"
    +"processor": "AMD A6"
    +"condition": "No"
    +"faults": "Light Damage,Heavy Damage"
    +"price": "16.37"
    +"name": "Alex"
    +"lastname": "C"
    +"email": "[email protected]"
    +"mobile": "12344567"
    +"created_at": "2016-02-20 09:05:51"
    +"updated_at": "2016-02-20 09:05:51"
  }
  1 => {#233 ▶}
  2 => {#234 ▶}

Now I would like to extract from each array(row) for example the name and do a for each on the view to show the names for each row.

How can I extract the values?

I tried this

foreach($inc_quotes as $quote){
        $quote_name = $quote->name;
    }

But only returns the last value.

Any help much appreciated.

2 Answers 2

3
$quote_name = [];
foreach($inc_quotes as $key => $quote){
        $quote_name[$key] = $quote->name;
    }

EDITED

pass this to view like this.

return view('whateverYourView',compact('quote_name'));

and in view you access it with

@foreach($quote_name as $name)
{{ $name }}
@endforeach
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks very much!! it did work. I was killing my brain all morning with this as I am just a beginner ;)
What about if I want to show in the view each row containing something like Your name is $quote_name and the price is $quote_price. How do I do the foreach loop in the view?
0

Your $quote_name must be an array or an collection to receive all data that is comming from the array that you are iterating. The $quote_name will be subscribed in every loop, that's why the method it will show only the last result.

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.