Level 6
Paginate it from your controller.
$comentarios = Comentario::paginate(20);
return view('example', compact('comentarios'));
Hello guys, Im trying to paginate a eloquent relation and im getting a lot of problems.
This is my model...
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\SoftDeletes;
class Modelo extends Model {
use softDeletes;
public $errors;
protected $table = 'modelos';
protected $dates = ['deleted_at'];
protected $fillable = ['id_usuario', 'foto_perfil', 'nome', 'slug', 'idade', 'id_cidade', 'sexo', 'altura', 'peso', 'quadris', 'atendimento_tipo', 'atendimento_lugar', 'cache', 'telefone1', 'telefone2', 'telefone3', 'cartao', 'perfil', 'publicado', 'status'];
public function fotos()
{
return $this->hasMany('App\Foto', 'id_modelo', 'id');
}
public function usuario()
{
return $this->hasOne('App\User', 'id', 'id_usuario');
}
public function comentarios()
{
return $this->hasMany('App\Comentario', 'id_modelo', 'id'); // i want to paginate this one...
}
public static function modeloBySlug($slug){
return Modelo::where('slug', '=', $slug)
->where('publicado', '=', '1')
->where('status', '=', '2')
->get();
}
}
can you guys please help me to solve it?
thank you in advance
Please or to participate in this conversation.