Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.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 流明雄辩的拯救()唐';t更新数据库中的数据_Php_Eloquent_Lumen - Fatal编程技术网

Php 流明雄辩的拯救()唐';t更新数据库中的数据

Php 流明雄辩的拯救()唐';t更新数据库中的数据,php,eloquent,lumen,Php,Eloquent,Lumen,我有买家模型,但当我想更改当前的it数据并保存它时,它不会保存$买方->保存()返回1,但我的数据库中的数据不会更改 附言。 我的数据库有id、created_at和updated_at字段。$buyer不是空的,它是我请求的数据对象('pCode'、'banked'、'hwid')) 我的代码 namespace App\Http\Controllers; use App\TGOBuyer as Buyer; class SubController extends Controller {

我有买家模型,但当我想更改当前的it数据并保存它时,它不会保存$买方->保存()返回1,但我的数据库中的数据不会更改

附言。 我的数据库有id、created_at和updated_at字段。$buyer不是空的,它是我请求的数据对象('pCode'、'banked'、'hwid'))

我的代码

namespace App\Http\Controllers;

use App\TGOBuyer as Buyer;

class SubController extends Controller
{
    public function ban($key){
        $buyer = Buyer::where('pCode', $key)->select('pCode', 'banned', 'hwid')->first();
        if (!$buyer || $buyer->banned)
            return response()->json(['wrong' => 'key']);

        $buyer->comment = 'test';
        $buyer->banned = 1;
        $buyer->save();
    }
}
买方型号 名称空间应用程序

use Illuminate\Database\Eloquent\Model;

class TGOBuyer extends Model {
    protected $table = 'buyers';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'banned', 'comment', 'pCode', 'hwid'
    ];
}
更新 我试图返回$buyer->id,它给我空值,我不明白为什么会发生

这是我的数据库

CREATE TABLE IF NOT EXISTS `buyers` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `pCode` varchar(20) NOT NULL,
  `banned` tinyint(1) NOT NULL DEFAULT '0',
  `comment` text NOT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `pCode` (`pCode`),
  UNIQUE KEY `id_2` (`id`),
  KEY `id` (`id`),
  KEY `hwid` (`hwid`),
  KEY `pID` (`pID`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=22468 ;

我明白了。我只需要在select查询中包含id。现在一切都好了

$buyer = Buyer::where('pCode', $key)->select('id', 'pCode', 'banned', 'hwid')->first();

我明白了。我只需要在select查询中包含id。现在一切都好了

$buyer = Buyer::where('pCode', $key)->select('id', 'pCode', 'banned', 'hwid')->first();