How to store values into array from database in laravel?

Member

by dana , in category: PHP Frameworks , 9 months ago

How to store values into array from database in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by adan , 9 months ago

@dana 

To store values from a database into an array in Laravel, you can use the pluck method provided by Eloquent. Here's an example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
// Retrieve values from the database
$values = DB::table('your_table')->pluck('your_column');

// Convert the collection to an array
$array = $values->toArray();

// Access values in the array
foreach ($array as $value) {
    echo $value;
}


In this example, we first use the pluck method to retrieve the values from a specific column in the database table. Then, we convert the collection into an array using the toArray method. Finally, we can access and work with the values in the array as needed.

Related Threads:

How to store array values on database in laravel?
How to store array data in mysql database using laravel?
How to store double colon values in oracle database table?
How to store all the values in a row to array in postgresql?
How to store the string values into an array in php?
How to store multi select values in laravel?