Skip to content

Commit

Permalink
Merge pull request #2 from NilesB/fix/meta-default-value
Browse files Browse the repository at this point in the history
Remove default on meta field
  • Loading branch information
DivineOmega authored Mar 12, 2019
2 parents 12e6efe + 0e78a33 commit f9d76c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class AddMetaToBasketItemsTable extends Migration
Expand All @@ -13,8 +14,13 @@ class AddMetaToBasketItemsTable extends Migration
*/
public function up()
{
Schema::table('basket_items', function (Blueprint $table) {
$table->text('meta')->default('[]');
$dbType = DB::connection()->getPDO()->getAttribute(PDO::ATTR_DRIVER_NAME);

Schema::table('basket_items', function (Blueprint $table) use ($dbType) {
$field = $table->text('meta');
if ($dbType === 'sqlite') {
$field->default('[]');
}
});
}

Expand Down
4 changes: 1 addition & 3 deletions src/Models/Basket.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ public function add(int $quantity, Basketable $basketable, array $meta = [])
$item->quantity = $quantity;
$item->basketable_type = get_class($basketable);
$item->basketable_id = $basketable->getKey();
if ($meta) {
$item->meta = $meta;
}
$item->meta = $meta;
$item->save();

unset($this->items);
Expand Down

0 comments on commit f9d76c3

Please sign in to comment.