Tengo la siguiente function
public function edit(categoryarea $categoryarea){
$this->categoryarea = $categoryarea;
}
Estoy intentado pasar pasar esto a una Array
para poder obtener solo ID de la siguinte manera:
$this->categoryareaarray = json_decode($this->categoryarea, true);
pero me esta devolviendo el siguiente error
ErrorException
htmlspecialchars() expects parameter 1 to be string, array given
también intente la siguiente consulta
$this->categoryareaarray = json_encode( (array) $this->categoryarea);
y me devuelve esto
"{\"\\u0000*\\u0000guarded\":[],\"\\u0000*\\u0000connection\":\"mysql\",\"\\u0000*\\u0000table\":\"category_areas\",\"\\u0000*\\u0000primaryKey\":\"id\",\"\\u0000*\\u0000keyType\":\"int\",\"incrementing\":true,\"\\u0000*\\u0000with\":[],\"\\u0000*\\u0000withCount\":[],\"preventsLazyLoading\":false,\"\\u0000*\\u0000perPage\":15,\"exists\":true,\"wasRecentlyCreated\":false,\"\\u0000*\\u0000attributes\":{\"id\":21,\"id_category\":18,\"id_area\":9,\"ans_cat\":5,\"duration_cat\":null,\"description\":null,\"created_at\":\"2021-07-14 16:35:28\",\"updated_at\":\"2021-07-17 03:14:32\"},\"\\u0000*\\u0000original\":{\"id\":21,\"id_category\":18,\"id_area\":9,\"ans_cat\":5,\"duration_cat\":null,\"description\":null,\"created_at\":\"2021-07-14 16:35:28\",\"updated_at\":\"2021-07-17 03:14:32\"},\"\\u0000*\\u0000changes\":[],\"\\u0000*\\u0000casts\":[],\"\\u0000*\\u0000classCastCache\":[],\"\\u0000*\\u0000dates\":[],\"\\u0000*\\u0000dateFormat\":null,\"\\u0000*\\u0000appends\":[],\"\\u0000*\\u0000dispatchesEvents\":[],\"\\u0000*\\u0000observables\":[],\"\\u0000*\\u0000relations\":[],\"\\u0000*\\u0000touches\":[],\"timestamps\":true,\"\\u0000*\\u0000hidden\":[],\"\\u0000*\\u0000visible\":[],\"\\u0000*\\u0000fillable\":[]}"
Alguien me podría decir que estoy haciendo mal y que debo hacer para obtener el ID en modo de Array
, ya que necesito el ID para hacer una nueva consulta..
Gracias
Si tomo la varible $categoryarea
y lo paso por un dd me devuelve lo siguiente:
App\Models\categoryarea\categoryArea {#1421 ▼
#guarded: []
#connection: "mysql"
#table: "category_areas"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:8 [▼
"id" => 21
"id_category" => 18
"id_area" => 9
"ans_cat" => 5
"duration_cat" => null
"description" => null
"created_at" => "2021-07-14 16:35:28"
"updated_at" => "2021-07-17 03:14:32"
]
#original: array:8 [▼
"id" => 21
"id_category" => 18
"id_area" => 9
"ans_cat" => 5
"duration_cat" => null
"description" => null
"created_at" => "2021-07-14 16:35:28"
"updated_at" => "2021-07-17 03:14:32"
]
#changes: []
#casts: []
#classCastCache: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: []
}