Skip to content

Commit

Permalink
Refactor lazy cart table migration code
Browse files Browse the repository at this point in the history
The commit simplifies the constructor in the lazy cart table migration file. Unnecessary uses are removed, the $modelTableResolver property isn't stored anymore, and instances of it are directly accessing the necessary methods. The "up" and "down" methods were also updated to explicitly return void.
  • Loading branch information
CrazyBoy49z committed Jul 7, 2024
1 parent 724ccca commit 36ac375
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions database/migrations/create_lazy_cart_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Step2Dev\LazyCart\Models\Cart;
use Step2Dev\LazyCart\Models\CartItem;
use Step2Dev\LazyCart\Support\ModelTableResolver;

return new class extends Migration {
protected $modelTableResolver;
protected string $userModel;
protected string $cartModel;
protected string $cartItemModel;
Expand All @@ -17,17 +14,15 @@ return new class extends Migration {

public function __construct()
{
/** @var ModelTableResolver $modelTableResolver */
$modelTableResolver = app(ModelTableResolver::class);
$this->modelTableResolver = $modelTableResolver;
$this->userModel = $this->modelTableResolver->getUserModel();
$this->cartModel = $this->modelTableResolver->getCartClass();
$this->cartItemModel = $this->modelTableResolver->getCartItemClass();
$this->cartTable = $this->modelTableResolver->getCartTable();
$this->cartItemTable = $this->modelTableResolver->getCartItemTable();
$this->userModel = $modelTableResolver->getUserModel();
$this->cartModel = $modelTableResolver->getCartClass();
$this->cartItemModel = $modelTableResolver->getCartItemClass();
$this->cartTable = $modelTableResolver->getCartTable();
$this->cartItemTable = $modelTableResolver->getCartItemTable();
}

public function up()
public function up(): void
{
Schema::create($this->cartTable, function (Blueprint $table) {
$table->id();
Expand All @@ -46,7 +41,7 @@ return new class extends Migration {
});
}

public function down()
public function down(): void
{
Schema::dropIfExists($this->cartItemModel);
Schema::dropIfExists($this->cartTable);
Expand Down

0 comments on commit 36ac375

Please sign in to comment.