Skip to content
Advertisement

Create view in one controller and store data in other controller laravel

I’m new to Laravel and I’m trying to store a form. I created the view with the House controller but now I want to store the data in the view with the Booking controller. But when I click the button nothing happens.

My question is if it is possible to make a view with one controller and store it with another controller or maybe there is an other solution.

I also want to use the id of the house to store. How do I get that in the other controller as well?

Web Route

JavaScript

Booking controller

JavaScript

House controller

JavaScript

View

JavaScript

Advertisement

Answer

First of all, nothing happens when you click the form submit button because it is currently type="button" and in order this button to play role of submission button it must be type="submit". You can do whatever you want with Laravel. If you want your form to hit another controller method you can simply specify that in your form tag. Like so:

Imagine this is a form inside a view that is rendered by HouseController

JavaScript

And now on form submission inside a view that is rendered by HouseController, you will actually hit a route that is BookingController responsive for. And here is your route that is being hit by the form

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