UsmanBasharmal
6 months ago
1135
6
Laravel

After removing pagination could not get the data via api Laravel/Vuejs

Posted 6 months ago by UsmanBasharmal

I have applied serverside pagination but it didn't work with Datatables so I removed it but now I could not get the data from my BookController via API if I put the pagination back it works I don't know what is wrong.

here is my Bookcontroller

public function index()
    {
        try {
            // $Book = Book::orderBy('name', 'ASC')->paginate(10);
            $Book = Book::orderBy('name', 'ASC')->get();
            return response()->json($Book);
        } catch (Exception $e) {
            return response()->json($e->getMessage(), 500);
        }
    }

here is API

Route::apiResources(['Book'=>'API\BookController']);

here is some code of Book.vue

export default {
    data() {
        return {
           
            Books: {},
}
methods: {
loadallBooks() {
            axios.get("api/Book").then(({ data }) => (this.Books = data));
        },
created() {
        this.loadBooks();
        Fire.$on("refreshPage", () => {
            this.loadBooks();
        });
    }
}

}

Please sign in or create an account to participate in this conversation.