### Install and Run Docker Environment Source: https://github.com/lunarphp/livewire-starter-kit/blob/main/README.md Copies the Docker environment example file to .env and starts the Docker containers for the demo store. This requires Docker to be installed locally. The demo store will be accessible at http://localhost. ```bash cp .env.docker.example .env docker-compose up ``` -------------------------------- ### Docker development setup (Bash) Source: https://context7.com/lunarphp/livewire-starter-kit/llms.txt Commands to start a complete Docker-based development environment. Includes PHP, MySQL, Redis, and Nginx services. First-time setup requires environment file copy. ```bash # Copy Docker environment configuration cp .env.docker.example .env # Start Docker containers docker-compose up # The application will be available at http://localhost # Lunar admin panel: http://localhost/lunar # Default credentials: admin@lunarphp.io / password ``` -------------------------------- ### Lando local development (Bash) Source: https://context7.com/lunarphp/livewire-starter-kit/llms.txt Alternative development environment setup using Lando. Includes commands for database setup and demo data import. Provides HTTPS local URL by default. ```bash # Copy Lando environment configuration cp .env.lando.example .env # Start Lando environment lando start # Run migrations and seed demo data lando artisan migrate --seed # Import demo products and collections lando artisan lunar:import:products ``` -------------------------------- ### Configure environment variables (Bash) Source: https://context7.com/lunarphp/livewire-starter-kit/llms.txt Basic environment configuration for Laravel application setup. Includes database, payment, and session settings. Required before initial application boot. ```bash # Copy environment file cp .env.example .env # Key configuration variables APP_NAME=Laravel APP_URL=http://demo-store.test APP_DEBUG=true # Database configuration DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=demostore DB_USERNAME=root DB_PASSWORD= # Stripe payment integration STRIPE_KEY=pk_test_your_key_here STRIPE_SECRET=sk_test_your_secret_here # Session and cache CACHE_DRIVER=file SESSION_DRIVER=file SESSION_LIFETIME=120 # Generate application key php artisan key:generate ``` -------------------------------- ### Get authenticated user (PHP/Laravel Sanctum) Source: https://context7.com/lunarphp/livewire-starter-kit/llms.txt API endpoint for retrieving authenticated user details using Sanctum token authentication. Returns basic user information in JSON format. Requires Sanctum middleware setup. ```php get('/user', function (Request $request) { return $request->user(); }); ``` -------------------------------- ### GET /api/user Source: https://context7.com/lunarphp/livewire-starter-kit/llms.txt This endpoint retrieves information about the authenticated user using Laravel Sanctum token authentication. It requires a valid Bearer token in the Authorization header. Useful for client-side applications needing user profile data. ```APIDOC ## GET /api/user ### Description Retrieve the currently authenticated user details. ### Method GET ### Endpoint /api/user ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example Headers: Authorization: Bearer {token} ### Response #### Success Response (200) - **id** (integer) - User ID - **name** (string) - User name - **email** (string) - User email #### Response Example { "id": 1, "name": "John Doe", "email": "john@example.com" } ``` -------------------------------- ### Product Page with Variants - Livewire Source: https://context7.com/lunarphp/livewire-starter-kit/llms.txt Displays individual product details with variant selection. It fetches product data by slug, handles option selection, and determines the currently selected variant. Dependencies include Lunar's Product and ProductVariant models, and a custom FetchesUrls trait. ```php url = $this->fetchUrl( $slug, (new Product)->getMorphClass(), [ 'element.media', 'element.variants.basePrices.currency', 'element.variants.basePrices.priceable', 'element.variants.values.option', ] ); if (!$this->url) { abort(404); } // Pre-select first available option for each product option $this->selectedOptionValues = $this->productOptions->mapWithKeys(function ($data) { return [$data['option']->id => $data['values']->first()->id]; })->toArray(); } public function getVariantProperty(): ProductVariant { return $this->product->variants->first(function ($variant) { return !$variant->values->pluck('id') ->diff(collect($this->selectedOptionValues)->values()) ->count(); }); } public function getProductProperty(): Product { return $this->url->element; } public function render() { return view('livewire.product-page'); } } // Route definition Route::get('/products/{slug}', ProductPage::class)->name('product.view'); // Usage: Visit /products/premium-t-shirt to view product ``` -------------------------------- ### Search products with pagination (PHP/Livewire) Source: https://context7.com/lunarphp/livewire-starter-kit/llms.txt Implements a product search feature with URL-parameter synchronization using Livewire. Searches Lunar's product models with pagination support. Requires Lunar Models and Livewire WithPagination trait. ```php term)->paginate(50); } public function render() { return view('livewire.search-page'); } } // Route definition Route::get('search', SearchPage::class)->name('search.view'); ``` -------------------------------- ### Home Page Component - Livewire Source: https://context7.com/lunarphp/livewire-starter-kit/llms.txt Displays the storefront homepage, featuring collections and products. It fetches 'sale' collections and random product collections. Dependencies include Lunar's Collection and Url models. It returns a Livewire view. ```php getMorphClass()) ->whereSlug('sale') ->first()?->element ?? null; } public function getSaleCollectionImagesProperty() { if (!$this->getSaleCollectionProperty()) { return null; } $collectionProducts = $this->getSaleCollectionProperty() ->products() ->inRandomOrder() ->limit(4) ->get(); return $collectionProducts->map(function ($product) { return $product->thumbnail; })->chunk(2); } public function getRandomCollectionProperty(): ?Collection { $collections = Url::whereElementType((new Collection)->getMorphClass()); if ($this->getSaleCollectionProperty()) { $collections = $collections->where('element_id', '!=', $this->getSaleCollectionProperty()?->id); } return $collections->inRandomOrder()->first()?->element; } public function render() { return view('livewire.home'); } } // Route definition in routes/web.php Route::get('/', Home::class); ``` -------------------------------- ### Collection Page Display with Livewire and LunarPHP Source: https://context7.com/lunarphp/livewire-starter-kit/llms.txt Displays product collections using Livewire and LunarPHP. It fetches collection data based on a provided slug and eagerly loads associated product information, including variants and prices. The component handles cases where the collection is not found by returning a 404 error. ```php url = $this->fetchUrl( $slug, (new CollectionModel)->getMorphClass(), [ 'element.thumbnail', 'element.products.variants.basePrices', 'element.products.defaultUrl', ] ); if (!$this->url) { abort(404); } } public function getCollectionProperty() { return $this->url->element; } public function render() { return view('livewire.collection-page'); } } // Route definition Route::get('/collections/{slug}', CollectionPage::class)->name('collection.view'); // Usage: Visit /collections/summer-sale to view collection ``` -------------------------------- ### Multi-Step Checkout Process with Livewire and LunarPHP Source: https://context7.com/lunarphp/livewire-starter-kit/llms.txt Implements a complete checkout flow including shipping address, billing address, shipping options, and payment processing. It utilizes LunarPHP's CartSession, Payments, and ShippingManifest facades. The component manages different checkout steps and validates user input for addresses. ```php 1, 'shipping_option' => 2, 'billing_address' => 3, 'payment' => 4, ]; protected $listeners = [ 'cartUpdated' => 'refreshCart', 'selectedShippingOption' => 'refreshCart', ]; public function mount(): void { if (!$this->cart = CartSession::current()) { $this->redirect('/'); return; } $this->shipping = $this->cart->shippingAddress ?: new CartAddress; $this->billing = $this->cart->billingAddress ?: new CartAddress; $this->determineCheckoutStep(); } public function saveAddress(string $type): void { $validatedData = $this->validate($this->getAddressValidation($type)); $address = $this->{$type}; if ($type == 'billing') { $this->cart->setBillingAddress($address); $this->billing = $this->cart->billingAddress; } if ($type == 'shipping') { $this->cart->setShippingAddress($address); $this->shipping = $this->cart->shippingAddress; if ($this->shippingIsBilling) { $this->cart->setBillingAddress($address); $this->billing = $this->cart->billingAddress; } } $this->determineCheckoutStep(); } public function saveShippingOption(): void { $option = $this->shippingOptions->first( fn($option) => $option->getIdentifier() == $this->chosenShipping ); CartSession::setShippingOption($option); $this->refreshCart(); $this->determineCheckoutStep(); } public function checkout() { $payment = Payments::cart($this->cart)->withData([ 'payment_intent_client_secret' => $this->payment_intent_client_secret, 'payment_intent' => $this->payment_intent, ])->authorize(); if ($payment->success) { redirect()->route('checkout-success.view'); return; } return redirect()->route('checkout-success.view'); } public function getShippingOptionsProperty() { return ShippingManifest::getOptions($this->cart); } protected function getAddressValidation(string $type): array { return [ "{$type}.first_name" => 'required', "{$type}.last_name" => 'required', "{$type}.line_one" => 'required', "{$type}.country_id" => 'required', "{$type}.city" => 'required', "{$type}.postcode" => 'required', "{$type}.contact_email" => 'required|email', "{$type}.contact_phone" => 'nullable', ]; } public function render() { return view('livewire.checkout-page')->layout('layouts.checkout'); } } // Route definition Route::get('checkout', CheckoutPage::class)->name('checkout.view'); ``` -------------------------------- ### Fetch URLs with eager loading (PHP/Laravel) Source: https://context7.com/lunarphp/livewire-starter-kit/llms.txt Reusable trait for querying Lunar URL models with optional eager loading. Handles default product URLs with relationship loading. Works with any Lunar model type that has URLs. ```php whereDefault(true) ->whereSlug($slug) ->with($eagerLoad) ->first(); } } ``` -------------------------------- ### Add to Cart Component in PHP Source: https://context7.com/lunarphp/livewire-starter-kit/llms.txt This component handles adding purchasable items to the shopping cart. It includes quantity validation and stock checking to ensure accurate cart management. This uses Livewire and LunarPHP. ```php 'required|numeric|min:1|max:10000', ]; } public function addToCart(): void { $this->validate(); if ($this->purchasable->stock < $this->quantity) { $this->addError('quantity', 'The quantity exceeds the available stock.'); return; } CartSession::manager()->add($this->purchasable, $this->quantity); $this->dispatch('add-to-cart'); } public function render() { return view('livewire.components.add-to-cart'); } } // Blade usage example in product-page.blade.php: // ``` -------------------------------- ### Shopping Cart Management in PHP Source: https://context7.com/lunarphp/livewire-starter-kit/llms.txt This Livewire component manages cart contents including updating line items, changing quantities, and removing items. It uses LunarPHP's CartSession facade for cart operations and provides event dispatching for UI updates. ```php 'handleAddToCart', ]; public function rules(): array { return [ 'lines.*.quantity' => 'required|numeric|min:1|max:10000', ]; } public function mount(): void { $this->mapLines(); } public function getCartProperty() { return CartSession::current(); } public function updateLines(): void { $this->validate(); CartSession::updateLines(collect($this->lines)); $this->mapLines(); $this->dispatch('cartUpdated'); } public function removeLine($id): void { CartSession::remove($id); $this->mapLines(); } public function mapLines(): void { $this->lines = $this->cart->lines->map(function ($line) { return [ 'id' => $line->id, 'identifier' => $line->purchasable->getIdentifier(), 'quantity' => $line->quantity, 'description' => $line->purchasable->getDescription(), 'thumbnail' => $line->purchasable->getThumbnail()?->getUrl(), 'options' => $line->purchasable->getOptions()->implode(' / '), 'sub_total' => $line->subTotal->formatted(), 'unit_price' => $line->unitPrice->formatted(), ]; })->toArray(); } public function handleAddToCart(): void { $this->mapLines(); $this->linesVisible = true; } public function render() { return view('livewire.components.cart'); } } // Wire up cart updates with Livewire events // In add-to-cart component: $this->dispatch('add-to-cart'); // Cart component listens and updates automatically ``` -------------------------------- ### Add custom shipping options (PHP/Lunar) Source: https://context7.com/lunarphp/livewire-starter-kit/llms.txt Cart modifier that adds basic shipping option when table-rate shipping is disabled. Uses Lunar's ShippingManifest to register custom options with tax class support. Requires Lunar Models and ShippingManifest facade. ```php currency, 1), taxClass: TaxClass::getDefault() ) ); } return $next($cart); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.