php - What is the alternative of fetching multiple queries in Laravel? -


i'm bit confused eloquent , how works. want know way im on not bad practice or kind of overhead eloquent orm. part of classroom model

static function classgradelist(){     return classroom::select('classgrade')         ->groupby('classgrade')         ->orderby('classgrade')         ->get(); } static function classsectionlist(){     return classroom::select('classgrade','classsection')         ->groupby('classgrade','classsection')         ->orderby('classsection')         ->get(); } static function classnamelist(){     return classroom::select('classgrade','classsection','classname')         ->orderby('classname')         ->get(); } 

the reason behind these functions create list 3 separate area on same view. call them below in same view:

<ul id="classsections" class="dropdown-menu">             @foreach(app\classroom::classsectionlist() $csect)                 <li onclick="csselect(this)" data-cg="{{$csect->classgrade}}" data-cs="{{$csect->classsection}}" class="classsection">                     <a>{{$csect->classsection}}</a>                 </li>             @endforeach         </ul>   <ul id="classgrades" class="dropdown-menu">             @foreach(app\classroom::classgradelist() $cgrade)                 <li onclick="cgselect(this);" data-cg="{{$cgrade->classgrade}}" >                     <a>{{$cgrade->classgrade}}</a>                 </li>             @endforeach         </ul>  <ul id="classnames" class="dropdown-menu">             @foreach(app\classroom::classnamelist() $item)                 <li onclick="cnselect(this)" data-cg="{{$item->classgrade}}" data-cs="{{$item->classsection}}" data-cn="{{$item->classname}}" class="classname">                     <a>{{$item->classname}}</a>                 </li>             @endforeach         </ul> 

i think code have way overhead, want implement in better way fetching things once , query on in php scope , through sth builder laravel's native class.

thanks @devon's comment i've overcome problem collection, had bit of problem groupby function of collection couldn't take array of columns, made column collection combination of 2 target columns below.

$allclass->map(function ($classroom) {         $classroom['sectgrade'] = $classroom['classgrade'].".".$classroom['classsection'];         return $classroom;     }); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -