Ad
Laravel Access Values From Object In Object
In one of the controller function
$readings = Reading::orderBy('reading_date_time', 'DESC')->get();
dd($readings);
This gives
Illuminate\Database\Eloquent\Collection {#1883
#items: array:160 [
0 => App\Reading {#1722
#fillable: array:6 [ …6]
#connection: "mysql"
#table: "readings"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:8 [ …8]
#original: array:8 [ …8]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#guarded: array:1 [ …1]
}...
How can I access the actual values of readings table. And use them for operations like array_column().
Ad
Answer
This function already give you the result, and the result is collection.
You can call the attribute by single object in collection:
$readings->first()->reading_date_time;
and you can use method-pluck to get the attribute values from collection, it just like array_column
:
$readings->pluck('reading_date_time');
If you use array_column
, you can use method-toArray to change collection to array:
array_column($readings->toArray(), 'reading_date_time')
Ad
source: stackoverflow.com
Related Questions
- → How do I create an array from a single form input box with php on octobercms?
- → Print the output value of an array in twig [OctoberCMS]
- → Declare an array variable to the controller/component [Laravel, October CMS]
- → Removing a JavaScript property inside a specific Object within an Array
- → Javascript loop indexing issue
- → search array without duplicates React.js
- → Populating array with items from different HTML attributes
- → Get all index value of 1 from binary "01000111"
- → Remove objects from array - Two different approaches, two different results when consulting the length of each array
- → Compare values in two arrays
- → adding multiple polygons in google maps using loops and arrays
- → .split() JS not "splitting" correctly?
- → Vue.js - Binding radio elements of same name to array
Ad