Skip to content

Instantly share code, notes, and snippets.

@AbdallaZaki
Last active April 1, 2017 02:49
Show Gist options
  • Save AbdallaZaki/9c181c977fe4f4da1d5018137865da9e to your computer and use it in GitHub Desktop.
Save AbdallaZaki/9c181c977fe4f4da1d5018137865da9e to your computer and use it in GitHub Desktop.
<?php
public function getGraphics($where,$count=10){
return Graphic::select(['title',
'content',
'graphics.user_id as user_id',
'graphics.id AS graphic_id',
'graphics.sub_category_id AS sub_category_id',
'sub_categories.category_id AS category_id',
'graphics.updated_at AS created_at',
'files.path','user.name','cat','subcat'])->
join('sub_categories','sub_categories.id','=','graphics.sub_category_id')->
join('categories','categories.id','=','sub_categories.category_id')->
join('users','users.id','=','graphics.user_id')->
join('fileables',function($query){
$query->on('graphics.id','=','fileables.fileable_id')
->orderBy('order','asc')->take(1);
})->join('graphic_license','graphic_license.graphic_id','=','graphics.id')->
join('licenses',function($query){
$query->on('licenses.id','=','graphic_license.license_id')
->orderBy('price','asc')->take(1);
})->join('files','files.id','=','fileables.file_id')
->where($where)->groupBy('graphics.id')->
orderBy('graphics.updated_at','DESC')->take($count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment