ssquare
1 week ago
36
12
Laravel

Form is not being posting to the intended route, what should I double check

Posted 1 week ago by ssquare

I am trying to submit form to the laravel. Instead of postIndex it is still sending its request to @index.

My form looks like this:

<form method="POST" action="{{route('amenityFront.postIndex')}}" id="buildingByProperty">
    @csrf
    <select class="form-control" name="property" id="propertySelect">
        @foreach($properties as $pk => $pv)
            <option value="{{$pv->id}}" {{ ($pv->id == $selectedProperty)?'selected':'' }}>{{$pv->property_name}}</option>
        @endforeach
    </select>
    <button type="submit">Submit</button>
</form>

and route:

Route::get('/', ['as' => 'amenityFront.index', 'uses' => '[email protected]']);
    Route::post('/', ['as' => 'amenityFront.postIndex', 'uses' => '[email protected]']);

However, instead of redirecting to postIndex I am still being posted to @index

My route:list screenshot

https://ibb.co/LkJqQV8

Even more surprising, even on @index, if I try to print_r($request->all()) it display an empty array:

Array
(
)

By the way my controller:

public function postIndex(Request $request)
    {
        echo "zz";
        exit();
    }

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