Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 538 Vote(s) - 3.43 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Group By Eloquent ORM

#1
I was searching for making a `GROUP BY name` [Eloquent ORM docs][1] but I haven't find anything, neither on google.

Does anyone know if it's possible ? or should I use query builder ?


[1]:

[To see links please register here]

Reply

#2
Eloquent uses the query builder internally, so you can do:

$users = User::orderBy('name', 'desc')
->groupBy('count')
->having('count', '>', 100)
->get();
Reply

#3
try: ```->unique('column') ```

example:

``` $users = User::get()->unique('column');```
Reply

#4
# Laravel 5

> **WARNING**: As @Usama stated in comments section, this groups by AFTER fetching data from the database. The grouping is not done by the database server.
_I wouldn't recommend this solution for large data set._


This is working for me (i use **laravel 5.6**).

$collection = MyModel::all()->groupBy('column');

If you want to convert the collection to plain php array, you can use **toArray()**

$array = MyModel::all()->groupBy('column')->toArray();
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through