Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel SQL选择和更新模型_Php_Laravel_Laravel 4 - Fatal编程技术网

Php Laravel SQL选择和更新模型

Php Laravel SQL选择和更新模型,php,laravel,laravel-4,Php,Laravel,Laravel 4,我尝试从数据库中选择并使用模型更新值,但出现错误: Call to undefined method stdClass::save() 我的代码: $user = db::table('users')->where('name', 'John')->where('age', 30)->first(); if($user) { $user->name = 'Tom'; $user->age = 31; $user->save(); }

我尝试从数据库中选择并使用模型更新值,但出现错误:

Call to undefined method stdClass::save()
我的代码:

$user = db::table('users')->where('name', 'John')->where('age', 30)->first();
if($user) {
    $user->name = 'Tom';
    $user->age = 31;
    $user->save();
}

我得到了这个错误:

如果您想使用
save()
您必须使用实际的模型来构建查询。目前,您只是从db中选择了一些东西,而没有对模型进行水合处理

$user = User::where('name', 'John')->where('age', 30)->first();
if($user) {
    $user->name = 'Tom';
    $user->age = 31;
    $user->save();
}

如果要使用
save()
,必须使用实际模型构建查询。目前,您只是从db中选择了一些东西,而没有对模型进行水合处理

$user = User::where('name', 'John')->where('age', 30)->first();
if($user) {
    $user->name = 'Tom';
    $user->age = 31;
    $user->save();
}

如果要使用
save()
,必须使用实际模型构建查询。目前,您只是从db中选择了一些东西,而没有对模型进行水合处理

$user = User::where('name', 'John')->where('age', 30)->first();
if($user) {
    $user->name = 'Tom';
    $user->age = 31;
    $user->save();
}

如果要使用
save()
,必须使用实际模型构建查询。目前,您只是从db中选择了一些东西,而没有对模型进行水合处理

$user = User::where('name', 'John')->where('age', 30)->first();
if($user) {
    $user->name = 'Tom';
    $user->age = 31;
    $user->save();
}

我认为
db
应该是
db
我认为
db
应该是
db
我认为
db
应该是
db
我认为
db
应该是
db