[英]How can i pass a variable with route in laravel form action?
我收到这个错误...
syntax error, unexpected '}', expecting ')'
<form action="<?php echo e(url('/update/{{$id); ?>')}} " method="post">
如果我像这样使用<form action="{{url('/anyroute/')}} " method="post">
它工作正常。 但是如果我用这个传递一个$id,它就不起作用。 下面是我正在使用的代码..
<form action="{{url('/update/{{$id}}')}} " method="post">
</form>
使用命名路由 ,然后您将拥有更清晰可读的代码:
在路线:
Route::post('/update/{id}', 'SomeController@update')->name('something.update');
在视图中:
<form action="{{ route('something.update', ['id' => $id]) }}" method="post">
...
</form>
您可以像这样在 laravel 9 中传递它
<form action="{{ route('user.update', [$user->id]) }}" method="post">
</form>
Route::post('/update/{id}', [UserProfileController::class, 'update'])>name('user.update');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.