Skip to content
Advertisement

Laravel: Displaying data from db after clicking a button – but staying on the same page

That’s the task I am currently facing:

Starting point: I have a form, which accepts data and saves it into the database.

What needs to be done: I need to include a button called “show data” (a different one than the “submit” button in the form, it can even be a clickable div), which will then display the data from the database on the same page, under the form. The button should also enable refreshing the list after new data was inserted into the form.

Now, if the data from the database had to be displayed on a different page, that could be handled easily with routing. However, for this particular task, I need to display the data on the same page.

My question: Is there a pure Laravel/PHP way to solve that problem? I am considering using AJAX (to which I am also new), but if there is some Laravel specific solution then I would prefer that.

The solution needs to work on localhost.

Advertisement

Answer

For PHP, without having any help from JavaScript, showing any changes to the database will require a browser refresh. On the front-end, you can use VueJS and Axios to help you with these requests, which do not require the browser to be refreshed.

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