【发布时间】:2017-12-05 09:11:48
【问题描述】:
我正在使用 Crinsane/LaravelShoppingcart 包,我在迁移它时在购物车表上进行了一些编辑并像这样添加
Schema::create(config('cart.database.table'), function (Blueprint $table) {
$table->string('identifier');
$table->integer('userId')->unsigned();
$table->text('address');
$table->string('instance');
$table->longText('content');
// $table->nullableTimestamps();
$table->timestamps();
$table->primary(['identifier', 'instance']);
$table->foreign('userId')->references('id')->on('users')->onDelete('cascade');
});
并且还像这样在 Cart 类中编辑了 store 方法(添加了两个参数来存储 $userId 和 $address)
public function store($identifier, $address, $userId)
{
$content = $this->getContent();
if ($this->storedCartWithIdentifierExists($identifier)) {
throw new CartAlreadyStoredException("A cart with identifier {$identifier} was already stored.");
}
$this->getConnection()->table($this->getTableName())->insert([
'identifier' => $identifier,
'address' => $address,
'userId' => $userId,
'instance' => $this->currentInstance(),
'content' => serialize($content)
]);
$this->events->fire('cart.stored');
}
并且在数据库中一切正常,但问题是当我使用恢复方法从数据库恢复数据时,仅使用一个参数($identifier)恢复它什么也没给我,当我 dd(Cart::restore(Auth ::user()->id)) 它给了我“null”请帮我解决这个问题
【问题讨论】:
标签: php database laravel e-commerce laravel-5.5