Firas
Firas

Reputation: 23

Laravel can't post data to controller

This is my form and I'm trying to send the id and the title of a product to the controller but I have no clue why I got null as a value.

show.blade.php:

<form action="{{ route('cart.store') }}" method="POST">
    @csrf
    <input type="hidden" name="product_id" value="{{ $product->id }}">
    <input type="hidden" name="product_name" value="{{ $product->title }}">
    <button type="submit" class="ps-btn mb-10">J'encheris <i class="ps-icon-next"></i></button>
</form>

web.php:

Route::post('/MesEnchers/ajouter', 'CartController@store')->name('cart.store');

CartController.php :

public function store(Request $request)
{
    dd($request->id, $request->title);
}

enter image description here

Upvotes: 2

Views: 981

Answers (1)

N69S
N69S

Reputation: 17206

Your variables are product_id & product_name not id & title

try

public function store(Request $request)
{
    dd($request->product_id, $request->product_name);
}

Upvotes: 3

Related Questions