0

im newb using laravel and hope someone helps me.

i have data details from database and get it with laravel collection ,here my code :

 public function index()
  {
    $corpus = V_Corpus::select('details')->pluck('details');

    dd($corpus);
  }

and the result var_dump is an array with structure like this:

Illuminate\Support\Collection {#205 ▼
  #items: array:3 [▼
   0 => "CPU Socket LGA1151 Chipset Intel Z390  4 x DIMM Max 64GB DDR4"
   1 => "CPU Socket LGA1151 Chipset Intel Z390  4 x DIMM Max 64GB DDR4"
   2 => "CPU Socket LGA1151 Chipset Intel Z390  4 x DIMM Max 64GB DDR4"
  ]
}

the problem is how can u change the array srtructure from the previous array to look like this :

array:3 [▼
   0 => "CPU Socket LGA1151 Chipset Intel Z390  4 x DIMM Max 64GB DDR4"
   1 => "CPU Socket LGA1151 Chipset Intel Z390  4 x DIMM Max 64GB DDR4"
   2 => "CPU Socket LGA1151 Chipset Intel Z390  4 x DIMM Max 64GB DDR4"
]

sorry for my bad english.

2 Answers 2

1

You can also get all the result always as array by changing

config/database.php

'fetch' => PDO::FETCH_CLASS,

to

'fetch' => PDO::FETCH_ASSOC,

Or modify the index function

public function index() {
    $corpus = V_Corpus::select('details')->pluck('details')->toArray();

    dd($corpus);
}

Hope this will help.

Sign up to request clarification or add additional context in comments.

Comments

0

i found it, just add toArray().

$corpus = V_Corpus::select('details')->pluck('details')->toArray();

dd($corpus);

the output look like this :

array:3 [▼
   0 => "CPU Socket LGA1151 Chipset Intel Z390  4 x DIMM Max 64GB DDR4"
   1 => "CPU Socket LGA1151 Chipset Intel Z390  4 x DIMM Max 64GB DDR4"
   2 => "CPU Socket LGA1151 Chipset Intel Z390  4 x DIMM Max 64GB DDR4"
]

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.