I have this code:
$modeloVideo = ModeloVideo::paginate(10);
I want to page by 10 and display order by desc
(descending order).
How to do this query?
I tried this way:
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\ModeloVideo;
class HomeController extends Controller {
public function home() {
//TODOS OS REGISTROS DA TABELA
$modeloVideo = ModeloVideo::all()->orderBy('created_at', 'desc')->paginate(10);
$array = array("videos" => $modeloVideo,
);
return view('home',$array);
}
Model code:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class ModeloVideo extends Model {
//informando a tabela que sera usada
protected $table = "modeloVideo";
//quando fizer uma insercao ou update nao adicionar a coluna created ou update
}
?>
and has not yet worked, gives the error: BadMethodCallException Method orderBy does not exist.