Is is a Good practice to write my Query inside Routes file ?
eg:
Route::get('popular', function(){
$media = Media::where('active', '=', '1')->join('media_likes', 'media.id', '=', 'media_likes.media_id')->groupBy('media_likes.media_id')->orderBy(DB::raw('COUNT(media_likes.id)'), 'DESC')->select('media.*')->paginate(30);
$data = array(
'media' => $media);
return View::make('home', $data);
});
As far as i knw that is the job of model file.
No, it's wrong if you are not building just a prototype app.
You should use controllers and models to separate your logic instead of closures on routes.
Take a look at Laracasts to learn more about more about MVC and Laravel in general, there are plenty of free lessons.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community