Why not change route to point to correct controller method? Also a suggestion, use resource controller or have better method names, like:
- makeBooking
- makeDetail
Something like that.
https://laravel.com/docs/8.x/controllers#resource-controllers
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have two forms in one page. Both of the tables have a separate models. Now i want to make insert to them. But as the tables are separate so there form are too separate. Also the laravel said that you can't duplicate a route which will result override. Now what is the solution for it.
class HomeController extends Controller
{
public function index()
{
return view('index');
}
public function make_booking(Request $request){
$request->validate([
'date_from' => 'required',
'date_to' => 'required',
'booking_time' => 'required',
'city' => 'required',
'people' => 'required',
'mobile' => 'required'
]);
Booking::create($request->all());
// return redirect()->back()->with('success', 'Booking has been succesfully submitted');
}//
public function make_plan_detail(Request $request){
PlanDetails::create($request->all());
// return redirect()->back()->with('plan', 'Your plan has been succesfully submitted');
}
}
this is my route:
Route::post('/', [HomeController::class, 'make_booking'])
->name('booking');
Route::get('/', [HomeController::class, 'index']);
in the view there
<form action="{{route('booking')}}" method="POST">
<button type="submit" class="btn btn-success" id="booking">Book Now</button>
</form>
<form action="{{route('booking')}}" method="POST">
<button type="submit" class="btn btn-success" id="plan_trip">Plan Trip</button>
</form>
@ziakhan Why does the url you store to matter? You redirect away from it anyways. No one will ever see the url, unless they check the browsers html source code.
Also.. there is no way to use the same url with two different methods.. When you post to /, laravel has no way of knowing which route you want to use.. They are the same.. / === /
It is (in theory) the same as saying
$POST_slash = [HomeController::class, 'make_plan_detail'];
$POST_slash = [HomeController::class, 'make_booking'];
Would you expect that to work?
If you for some reason MUST do this, then use the same method for a single route, and then in that method, use the proper "submethod"
Route::post('/', [HomeController::class, 'make_something'])
->name('booking');
//in controller
public function make_something(Request $request)
{
if ($request->type === 'booking') {
return $this->make_booking($request);
}
//else
return $this->make_plan_detail($request);
}
//and in the booking form
<input type="hidden" name="type" value="booking" />
Please or to participate in this conversation.