To get some information from the database in some moments is simpler to make a query with raw sql than to use several models, maps functions and a touch of magic to reach the same goal, however the problem of using a raw querie or a raw expression with ease we have to use the DB::select()
function and exactly this easiness that creates a problem that the return of the data is not compatible with the function of Laravel called pagination or Database Pagination that is already ready with the framework, in my case I tried to use it as follows in my controller :
$sql = "SELECT * FROM CLIENTES CL, PEDIDOS PD WHERE PD.ID_CLIENTE = CL.ID";
public function obterDados(){
return DB::select($sql)->simplePaginate(10);
}
Then the result returned is the error below:
Symfony\Component\Debug\Exception\FatalThrowableError (E_ERROR)
"Call to a member function simplePaginate() on array"
So how to use DB :: select () with the pagination function of the Laravel framework?