[英]Laravel how to pass null value in route parameter in front end
I have a form and I'm trying to pass null value into the $dev-id
parameter but it doesnt work, instead ti will replace the dev id parameter with the $id
as shown in my code at the bottom,我有一个表格,我正在尝试将 null 值传递给
$dev-id
参数,但它不起作用,而是 ti 将用$id
替换 dev id 参数,如底部代码所示,
The reason i needed it to be null because I'm using this function for 2 different page but one of the page doesn't have $dev_id
.我需要它的原因是 null 因为我将这个 function 用于 2 个不同的页面,但其中一个页面没有
$dev_id
。 any help is appreciated任何帮助表示赞赏
HTML: HTML:
<form method="post"
action="{{ route('admin.developers.admins.edit.post',['admin' => $admin, 'dev_id' => null, 'id' => $id]) }}" autocomplete="off" novalidate>
web.php: web.php:
Route::post('developers/{dev_id?}/admins/{id}/edit', 'Admin\DeveloperAdminController@postEditDeveloperAdmin')->name('admin.developers.admins.edit.post')->where(['dev_id' => '[0-9]+', 'id' => '[0-9]+']);
You can pass those parametres in the form of hidden input and in controller use request to get those values Add these to yur form您可以以隐藏输入的形式传递这些参数,并在 controller 使用请求获取这些值将这些添加到您的表单
<input type="hidden" value="anything" name="dev_id">
Instead you are using vue use `v-model` instead of name and value
Now modify your form like this现在像这样修改您的表单
<form method="post"
action="{{ route('admin.developers.admins.edit.post',['admin' => $admin,'id' => $id]) }}" autocomplete="off" novalidate>
Now you are access that using $request
object in your logic and check if the value is null or not现在您可以在逻辑中使用
$request
object 访问它,并检查该值是否为 null
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.