[英]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.