Bu query yöntemi 500 hatası veriyor yanlış ama doğrusunu buldum :
public function getIndex(){
$posts = Post::with(array('author'=>function($query){
$query->orderBy('created_at','DESC');
}))->where('id','<','10')->get();
return Response::json($posts);
}
Şimdi son bir sorun kaldı şu konuda bilginiz var mı. Mesela kalabalık bir indexim var. ben tüm bunları tek tek bind ediyordum. Bunları tek tek bind etmek mi yoksa hepsine ayrı fonksiyon ayarlayıp apiden çekmek mi doğru ?
public function getIndex()
{
$uri= Request::path();
$address = Request::url();
// Get all the blog categories
$categories = Category::all();
//Get Mainposts
$mainposts = Post::with(array('thumbnail' => function($query)
{
$query->orderBy('created_at','DESC');
}))->orderBy('created_at','DESC')->where('status','=',1)->take(8)->get();
$mainposts2 = Post::with(array('thumbnail' => function($query)
{
$query->orderBy('created_at','DESC');
}))->orderBy('created_at','ASC')->where('status','=',1)->take(5)->get();
$posts = Post::with('thumbnail')->orderBy(DB::raw('RAND()'))->where('status','=',1)->take(3)->get();
$mainbars = Haber::with(array('thumbnail' => function($query)
{
$query->orderBy('created_at','DESC');
}))->where('type','sirtcantalilar')
->where('status','=',1)
->orderBy('created_at', 'DESC')
->take(8)->get();
$sidebars = Haber::where('type','campaign')
->where('status','=',1)
->orderBy('created_at', 'DESC')
->take(5)->get();
$ournews = Haber::where('type','ournews')
->where('status','=',1)
->orderBy('created_at', 'DESC')
->take(6)->get();
$party2 = Haber::where('id',231)->first();
$party = Haber::where('type','ournews')->orderBy('created_at', 'DESC')->first();
$slidercampaigns = Haber::where('type','campaign')
->where('status','=',1)
->orderBy('created_at', 'DESC')
->take(4)->get();
$lastpost = Post::with('thumbnail')->orderBy('created_at','DESC')->where('status','=',1)->first();
$totalcount = Post::count();
$lasttwo = Post::with('thumbnail')->where('id', '<' ,$totalcount-1)
->orderBy(DB::raw('RAND()'))->where('status','=',1)->
take(2)->get();
$lastfifty = Post::with('thumbnail')->where('id', '<' ,150)
->orderBy(DB::raw('RAND()'))->where('status','=',1)
->take(3)->get();
$lasthundred = Post::with('thumbnail')->where('id', '>' ,50)
->where('id','<',150)
->orderBy(DB::raw('RAND()'))->where('status','=',1)
->first();
$slides = Post::where('slide_id',1)
// ->where('status','=',1)
->orderBy('created_at','DESC')->where('status',1)->get();
$bumerang = Haber::with('thumbnail')->where('id',163)->first();
$category1 = Category::find(33);
$bottomposts = $category1->posts()->where('status','=',1)->orderBy(DB::raw('RAND()'))->take(3)->get();
$category2 = Category::find(27);
$festivals= $category2->posts()->where('status','=',1)->orderBy(DB::raw('RAND()'))->take(3)->get();
$category3 = Category::find(35);
$foods= $category3->posts()->where('status','=',1)->orderBy(DB::raw('RAND()'))->take(4)->get();
$category4 = Category::find(25);
$housings= $category4->posts()->where('status','=',1)->orderBy(DB::raw('RAND()'))->take(3)->get();
return View::make('frontend/blog/index', compact('posts','sidebars','slidercampaigns','mainbars', 'categories','slides' ,'bottomposts','mainposts','festivals','foods','housings','bumerang','ournews','mainposts2' ,'count','lastpost','lasttwo','lastfifty','lasthundred','likes','party','party2','uri','address'));
}