In laravel 9.0 this code worked well and then I could use $result->property syntax in my blade view instead of array syntax $result['property']
public function getAllWithPaginator($perPage = null)
{
$columns = ['title','slug','category_id', 'image', 'fulltext', 'created_at'];
$categoryColumns = 'category:id,title,slug,image';
$result = $this
->startConditions()
->wherePublished(true)
->select($columns)
->with($categoryColumns)
->orderBy('created_at', 'DESC')
->get()
->toArray();
$result = Arr::arrayToObject($result);
$result = collect($result)->mypaginate($perPage);
return $result;
}
Now in Laravel 12 this gives error Method Illuminate\Support\Arr::arrayToObject does not exist.
How I can do it now?
Maybe Arr::arrayToObject was removed from framework to external package or there is another way to do it?
arrayToObjectfunction exists in laravel? Maybe you've modified the vendor file to add the function? I've checked the laravel/framework repository and found no such method on v9's release.->get()do give you the object(Illuminate\Database\Eloquent\Collection), no need for->toArray(). 2nd try to use inbuiltpaginationof laravel. You are getting all rows from database then doing the pagination, that will affect the performance.->get()outputs "heavy" object, whereas->toArray()contains only pure data.Eloquentquery in 1st place? its much slower than raw queryIlluminate\Support\Facades\DB