A fluent, convenient wrapper for working with arrays of data provided by Illuminate\Support\Collection class.
Questions tagged [laravel-collection]
368 questions
1
vote
2 answers
Method Illuminate\Database\Eloquent\Collection::delete does not exist
I'm working with Laravel 5.8 and in this project, I wanted to delete some data from a table in the DB, so I coded this at the Blade:
1
vote
3 answers
How to convert array and sub array to collection in Laravel?
I want to convert all of my static data to collection in Laravel.
This is my data:
static $menu_list = [
[
'path' => 'admin/report/transaction',
'active' => 'admin/report',
'name' => 'Report',
'icon' =>…

TaSvet
- 382
- 2
- 10
1
vote
1 answer
Sorting on a translable json column
I am using spatie translation package in laravel. I have collection which i want to sort by name but the name column has a json collection due to which its not getting sorted.
I have tried
$shoptype->categories->sortBy('name.en');
and my…

Wasim Rasheed
- 25
- 6
1
vote
1 answer
Laravel 8: How can I pass an additional parameter from controller to collection resource
I want to pass an additional parameter from controller to collection resource, Please have a look at the following code, I don't know why It's not working. I might be doing something wron here, please help
Controller
$batchStudents =…

Muhammad Owais
- 980
- 3
- 17
- 37
1
vote
3 answers
Looping through a Laravel collection to check for same value
I will appreciate any help on solving this please. I am working on Laravel project. I have a collection like so;
$products = Product::all();
Each product in the collection has a column called status, which is either set to 0, 1 or 2. Now I want to…

Flexi
- 197
- 11
1
vote
0 answers
Property exists but "does not exist on this collection instance." happens
"Exception
Property [delivery_cycle] does not exist on this collection instance."
Error occured.
But the property exists as far as I can see.
How should I fix it?
here is log.
local.DEBUG: :TEST_ABC:…

user14232549
- 405
- 4
- 17
1
vote
1 answer
How to persist a value between iterations in a Laravel Collection?
In my app, a Table can seat a certain number of diners. I need to write a collection that returns only the number of Tables I need to seat a given number of diners.
For example, if I have to seat four diners, and only have tables that seat one, I…

Cameron Scott
- 1,276
- 2
- 17
- 37
1
vote
0 answers
connecting a relationship between siblings in Php / Laravel / msql
I am currently connecting a relationship between siblings.
Issue: If Im on the main person with list of siblings and have record to database, but whenever I go to the one of the sibling, I can only view the main person, but not the other…

awthz Zei
- 87
- 1
- 8
1
vote
1 answer
Re-apply laravel where statement in a for each loop
How do i re-apply a where() statement on a certain collection while being in a for each loop.
Im currently looping my parameters and i want to for each them all in a where() statement so i can filter a collection with these where() statements
my…

Ser
- 167
- 1
- 1
- 14
1
vote
1 answer
Laravel collection with ampersand undefined property
I am dding a collection like so as I'm having a problem looking for a property on the object:
dd($this->plan);
Output:
Illuminate\Support\Collection {#5314
#items: array:3 [
"ageRange" => "Under 18"
"goal" => null
"duration" => &…

Lewis Smith
- 1,271
- 1
- 14
- 39
1
vote
1 answer
Property [roles] does not exist on this collection instance. in a many-to-many relationship
Hello I am learning relationship many to many I read the official documentation and use the conventions,
but I can't make the relation many to many I get the error that the property does not exist.
how can I solve…

Raydenz8
- 13
- 3
1
vote
0 answers
Laravel database collection property of non object in Blade
I have an issue with looping through a Laravel collection in a Blade component. The error I get is the following.
Trying to get property 'name' of non-object.
First of all, I query the database to get a list of categories with their…

Danny Younes
- 579
- 1
- 6
- 19
1
vote
2 answers
Sort By Alphabet then Numbers Laravel Collection
I am looking for a way to sort the collection in such a way that name values starting with the alphabet comes at the top and then name values that start with numbers. For example:
$collection = collect([
['name' => 'b', 'symbol' => '#'],
…

MAY
- 667
- 1
- 6
- 21
1
vote
1 answer
Rename Laravel Collection Key
I have a set of data dictionary $dataDictCollection
"column_a" => "Column A",
"column_b" => "Column B",
"column_c" => "Column C",
"column_d" => "Column D",
"column_e" => "Column E",
I have another set of result $resultCollection
[{
"column_a"…

mgg
- 61
- 10
1
vote
2 answers
Laravel filtered collection is no longer filtered after json encoding
I have an Eloquent collection with an eager loaded relationship. When I filter this eager loaded relationship, it works fine, but if I encode it as JSON (to pass it to my front end Javascript framework), the collection is no longer…

Greg Scott
- 13
- 5