Skip to content
Advertisement

Sorting of columns by joining two tables in Laravel

I have two tables books and publishers. publisher_id is primary key in publishers table and foreign key in books table. In index.blade.php of books, I want to create link for sorting of columns of book index. here is my that part of index.blade.php view where I am creating links.

JavaScript

And in BooksController.php, I have my index method in which sorting part is given below

JavaScript

Below is given my index view of books index.blade.php view

But When I click on publisher_name for sorting, it gives me an error like this.

JavaScript

So what can I do to solve it?

Advertisement

Answer

You can alias publishers.name to publisher_name, so that mysql can find the alias column:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement