Php Laravel-将函数参数传递给DB方法

Php Laravel-将函数参数传递给DB方法,php,database,laravel-5,Php,Database,Laravel 5,我有一个函数,它将id作为参数,并使用db方法更新db。但是,当我运行代码时,变量没有被传递给方法。为了测试,我用一个整数替换了$id,它工作了,所以我认为DB方法不能从参数访问变量 public function disable($id) { // Update the user status to 0 from 1 DB::table('employees')->where('id', $id)->update(['status' => 0]);

我有一个函数,它将id作为参数,并使用db方法更新db。但是,当我运行代码时,变量没有被传递给方法。为了测试,我用一个整数替换了$id,它工作了,所以我认为DB方法不能从参数访问变量

public function disable($id)
{

    // Update the user status to 0 from 1
    DB::table('employees')->where('id', $id)->update(['status' => 0]);
    return redirect('/employee')->with('error', 'User is disabled, all related accounts are now shutdown!...');
}
更新: 忘了提到我已经检查过了,参数在函数内部。好的,我可以在方法外部返回id

解决方案
如注释所示,varDump返回“id=9”,我需要“9”,我注意到在我的代码的表单部分中,在导致故障的id之前有一个额外的“id=”

使用函数作为
禁用(请求$Request)
并获取id作为
$Request->id

public function disable(Request $request)
{
    // Update the user status to 0 from 1
    DB::table('employees')->where('id', $request->id)->update(['status' => 0]);
    return redirect('/employee')->with('error', 'User is disabled, all related accounts are now shutdown!...');
}

发布使用非整数参数调用该方法的示例。该函数在请求中调用了吗?我认为您的
$id
参数是一个字符串,因此mysql无法匹配该id,请将其转换为整数作为
$id=(int)$id
,然后尝试在requestcall
dd($id)中调用它
在此函数中检查是否传递了
$id
,谢谢,但没有任何区别!。奇怪的是,我可以用数据库中的一个静态数字替换$id,然后运行更新。所以我知道这个方法很好,而且,我可以在方法运行后回显$id,所以我知道$id也会进来,但是他们彼此不说话!您在
/storage/logs/laravel.log
中得到了什么?