简体   繁体   中英

How can i pass a variable with route in laravel form action?

I'm getting this error...

syntax error, unexpected '}', expecting ')'
<form action="<?php echo e(url('/update/{{$id); ?>')}} " method="post">

if i use like this <form action="{{url('/anyroute/')}} " method="post">

It works fine. But if i pass a $id with this it doesn't work. The Below is the code i'm using..

<form action="{{url('/update/{{$id}}')}} " method="post">
</form>

Use named routes , then you'll have more clear and readable code:

In routes:

Route::post('/update/{id}', 'SomeController@update')->name('something.update');

In view:

<form action="{{ route('something.update', ['id' => $id]) }}" method="post">
...
</form>

use concatenation (.)

<form action="{{ url('/update/'. $id ) }} " method="post">
</form>

Documentation LINK

You can pass it in laravel 9 like so

<form action="{{ route('user.update', [$user->id]) }}" method="post">
</form>

Route::post('/update/{id}', [UserProfileController::class, 'update'])>name('user.update');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM