• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

1K
Vistas
Call to a member function links() on array in Laravel error

I was working with Laravel and I am trying to paginate my table of books. I got this error "Call to a member function links() on array in Laravel". It may be as the duplicate's error, but I still can't figure out how to solve my thing.

BookController fiddle:

public function index()
{
    $books = Book::simplePaginate(3)->all();
    $authors = Author::all();
    $genres = Genre::all();
    return view('books.all')->withBooks($books)->withAuthors($authors)->withGenres($genres);
}

books/all.blade.php fiddle

<table class="table table-hover">
  <tr class="info">
  <td>#</td>
  <td>Name</td>
  <td>Author</td>
  <td><center>Visit</center></td>
  </tr>
  @foreach($books as $book)
  <tr>
    <td width="50px"><img width="50px" height="75px" src="{{ asset('images/' . $book->image) }}"></td>
    <td width="50px">{{ $book->name }}</td>
    <td width="50px">{{ $book->author->name }}</td>
    <td width="50px"><center><a href="{{ url('books', $book->id) }}"><button class="btn btn-success">Visit</button></a></td>
 </tr>
@endforeach
</table> 
{{ $books->links() }}
almost 3 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Just remove the ->all() method from the $books variable.

$books = Book::paginate(10);

paginate() function considers taking all content from the table, which is taken here by Book model

almost 3 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda