How to form query?

Good time of day.

There is a block on the page to display a list of available servers
The accordion


And there is a table in the database with this structure...
 * @property int $id
 * @property string $hostname
 * @property string $name
 * @property string $city
 * @property string $location
 * @property string $country
 * @property string $country_code
 * @property string $continent
 * @property string $continent_code
 * @property boolean $torrenting_enabled
 * @property boolean $double_encryption
 * @property boolean $p2p
 * @property float $latitude
 * @property float $longtitude
 * @property boolean $visible
 * @property int $failed_check
 * @property boolean $white_label

Began the task to create a query to pull data from a table of data servers in such a way that you could easily vtulit it's all in the accordion shown above. Tobish grouping by continent and therefore the conclusion.
My poor brain was able to spit out only this:
$continents = ServersModels\Server::select('continent_code')
 ->orderBy('continent_code', 'ASC')

$servers = [];

foreach($continents as $continent){
 $continentCode = $continent->continent_code;
 $servers[$continentCode] = ServersModels\Server::where(['continent_code' => $continentCode, 'visible' => 1])->get();

But to generate four or more queries to fetch this - I do not think that a particularly good idea. Therefore, the question arose, how would it be possible to do better? Ideally in a single query.
I will be very happy and grateful for the links, clips, tips, tips :)

All beaver and key 13

Brain decided to spit out another solution. Your opinion?
$output = [];

$servers = ServersModels\Server::where(['visible' => 1])

foreach($servers as $server){
 $output[$server->continent_code]['continent'] = $server->continent;
 $output[$server->continent_code]['servers'][] = $server;
April 19th 20 at 12:01
0 answer

Find more questions by tags Laravel