0
我有買方模型,但是當我想更改當前數據並保存它時,它不會保存。 $ buyer-> save()返回1,但我的數據庫中的數據不會改變。Lumen Eloquent save()不更新數據庫中的數據
P.S. 我的數據庫有id,created_at和updated_at字段。和$買家是不是空的,它與數據對象,我請求( 'P碼', '禁止', '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'
];
}
更新 我tryed返回$與買方> 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 ;