1
I have that code:
$modeloVideo = ModeloVideo::paginate(10);
I want to page for 10 and display order by desc
(descending order).
How to do this query?
I tried so :
<?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 it hasn’t worked yet, but the error: Badmethodcallexception Method orderby does not exist.
I have no way to test it now, but I believe with
ModeloVideo::orderBy('created_at','desc')->paginate(10);
should work, but you will receive oneLengthAwarePaginator
and will have to treat... use thedd();
to test. Which version of the Laravel you are using?– sant0will