├── .editorconfig ├── .env.example ├── .gitattributes ├── .gitignore ├── .idea ├── .gitignore ├── codeStyles │ └── codeStyleConfig.xml ├── commandlinetools │ ├── Laravel_12_3_22__11_42_PM.xml │ └── schemas │ │ └── frameworkDescriptionVersion1.1.4.xsd ├── inspectionProfiles │ └── Project_Default.xml ├── laravel-ecommerce-inertia.iml ├── modules.xml ├── php.xml ├── phpunit.xml └── vcs.xml ├── .phpstorm.meta.php ├── README.md ├── _ide_helper.php ├── app ├── Actions │ ├── GetCart.php │ ├── GetOrderVariations.php │ ├── Search.php │ ├── ShowCategory.php │ └── ShowProduct.php ├── Cart │ ├── Cart.php │ ├── Contracts │ │ └── CartInterface.php │ └── Exceptions │ │ └── QuantityNoLongerAvailableException.php ├── Casts │ └── MoneyAttribute.php ├── Console │ ├── Commands │ │ └── Search │ │ │ └── SetupSearchFilters.php │ └── Kernel.php ├── Exceptions │ └── Handler.php ├── Http │ ├── Controllers │ │ ├── Auth │ │ │ ├── AuthenticatedSessionController.php │ │ │ ├── ConfirmablePasswordController.php │ │ │ ├── EmailVerificationNotificationController.php │ │ │ ├── EmailVerificationPromptController.php │ │ │ ├── NewPasswordController.php │ │ │ ├── PasswordController.php │ │ │ ├── PasswordResetLinkController.php │ │ │ ├── RegisteredUserController.php │ │ │ └── VerifyEmailController.php │ │ ├── CartController.php │ │ ├── CartVariationController.php │ │ ├── CategoryShowController.php │ │ ├── CheckoutController.php │ │ ├── Controller.php │ │ ├── HomeController.php │ │ ├── OrderConfirmationIndexController.php │ │ ├── OrderIndexController.php │ │ ├── OrderStoreController.php │ │ ├── PaymentIntentController.php │ │ ├── ProductShowController.php │ │ ├── ProfileController.php │ │ └── SearchController.php │ ├── Kernel.php │ ├── Middleware │ │ ├── Authenticate.php │ │ ├── CartMiddleware.php │ │ ├── EncryptCookies.php │ │ ├── HandleInertiaRequests.php │ │ ├── PreventRequestsDuringMaintenance.php │ │ ├── RedirectIfAuthenticated.php │ │ ├── RedirectIfCartEmpty.php │ │ ├── TrimStrings.php │ │ ├── TrustHosts.php │ │ ├── TrustProxies.php │ │ ├── ValidateSignature.php │ │ └── VerifyCsrfToken.php │ ├── Requests │ │ ├── Auth │ │ │ └── LoginRequest.php │ │ ├── PatchCartVariationRequest.php │ │ ├── PaymentIntentRequest.php │ │ ├── ProfileUpdateRequest.php │ │ ├── StoreCartVariationRequest.php │ │ └── StoreOrderRequest.php │ └── Resources │ │ ├── CartResource.php │ │ ├── CategoryResource.php │ │ ├── FilterResource.php │ │ ├── OrderResource.php │ │ ├── PaymentIntentResource.php │ │ ├── ProductResource.php │ │ ├── ShippingAddressResource.php │ │ ├── ShippingTypeResource.php │ │ └── VariationResource.php ├── Listeners │ └── AttachOrders.php ├── Mail │ ├── OrderCreated.php │ └── OrderStatusUpdated.php ├── Models │ ├── Cart.php │ ├── Category.php │ ├── Order.php │ ├── Product.php │ ├── Scopes │ │ └── LiveScope.php │ ├── ShippingAddress.php │ ├── ShippingType.php │ ├── Stock.php │ ├── User.php │ └── Variation.php ├── Observers │ └── OrderObserver.php ├── Providers │ ├── AppServiceProvider.php │ ├── AuthServiceProvider.php │ ├── BroadcastServiceProvider.php │ ├── CartServiceProvider.php │ ├── EventServiceProvider.php │ ├── RouteServiceProvider.php │ └── StripeServiceProvider.php └── Traits │ ├── HasFormattedPrice.php │ ├── HasImages.php │ ├── HasStock.php │ ├── MediaFile.php │ └── StockFigures.php ├── artisan ├── bootstrap ├── app.php └── cache │ └── .gitignore ├── composer.json ├── composer.lock ├── config ├── app.php ├── auth.php ├── broadcasting.php ├── cache.php ├── cart.php ├── cors.php ├── database.php ├── filesystems.php ├── hashing.php ├── ide-helper.php ├── logging.php ├── mail.php ├── media-library.php ├── money.php ├── queue.php ├── sanctum.php ├── scout.php ├── services.php ├── session.php ├── stripe.php └── view.php ├── database ├── .gitignore ├── factories │ ├── CartFactory.php │ ├── CategoryFactory.php │ ├── OrderFactory.php │ ├── ProductFactory.php │ ├── ShippingAddressFactory.php │ ├── ShippingTypeFactory.php │ ├── StockFactory.php │ ├── UserFactory.php │ └── VariationFactory.php ├── migrations │ ├── 2014_10_12_000000_create_users_table.php │ ├── 2014_10_12_100000_create_password_resets_table.php │ ├── 2019_08_19_000000_create_failed_jobs_table.php │ ├── 2019_12_14_000001_create_personal_access_tokens_table.php │ ├── 2022_11_30_220245_create_categories_table.php │ ├── 2022_12_04_184109_create_products_table.php │ ├── 2022_12_04_203415_create_variations_table.php │ ├── 2022_12_07_122402_create_stocks_table.php │ ├── 2022_12_09_115140_create_media_table.php │ ├── 2022_12_10_221151_create_carts_table.php │ ├── 2022_12_10_221648_creatr_cart_variation_table.php │ ├── 2022_12_19_073915_create_category_product_table.php │ ├── 2023_01_09_082248_create_shipping_types_table.php │ ├── 2023_01_10_095329_create_shipping_addresses_table.php │ ├── 2023_01_13_065822_create_orders_table.php │ ├── 2023_01_13_125310_create_order_variation_table.php │ └── 2023_01_17_204558_add_payment_intent_id_on_carts_table.php └── seeders │ ├── CartSeeder.php │ ├── CategorySeeder.php │ ├── DatabaseSeeder.php │ ├── OrderSeeder.php │ ├── ProductSeeder.php │ ├── ShippingAddressSeeder.php │ ├── ShippingTypeSeeder.php │ ├── StockSeeder.php │ ├── UserSeeder.php │ └── VariationSeeder.php ├── docker-compose.yml ├── jsconfig.json ├── lang └── en │ ├── auth.php │ ├── pagination.php │ ├── passwords.php │ └── validation.php ├── nike-air1-black.png ├── nike-air1-white.png ├── package-lock.json ├── package.json ├── phpunit.xml ├── postcss.config.js ├── public ├── .DS_Store ├── .htaccess ├── favicon.ico ├── images │ ├── .DS_Store │ └── no_image_available.png ├── index.php └── robots.txt ├── resources ├── css │ └── app.css ├── js │ ├── Components │ │ ├── ApplicationLogo.vue │ │ ├── Cart │ │ │ ├── Cart.vue │ │ │ └── CartItem.vue │ │ ├── Checkbox.vue │ │ ├── DangerButton.vue │ │ ├── Dropdown.vue │ │ ├── DropdownLink.vue │ │ ├── GlobalSearch.vue │ │ ├── Icon.vue │ │ ├── InputError.vue │ │ ├── InputLabel.vue │ │ ├── LinkButton.vue │ │ ├── Modal.vue │ │ ├── NavLink.vue │ │ ├── Navigation.vue │ │ ├── PrimaryButton.vue │ │ ├── Products │ │ │ ├── Category.vue │ │ │ ├── NotificationBox.vue │ │ │ ├── ProductBrowser.vue │ │ │ ├── ProductDropdown.vue │ │ │ ├── ProductGallery.vue │ │ │ └── ProductSelector.vue │ │ ├── ResponsiveNavLink.vue │ │ ├── SecondaryButton.vue │ │ ├── Select.vue │ │ └── TextInput.vue │ ├── Layouts │ │ ├── AppLayout.vue │ │ └── GuestLayout.vue │ ├── Pages │ │ ├── Auth │ │ │ ├── ConfirmPassword.vue │ │ │ ├── ForgotPassword.vue │ │ │ ├── Login.vue │ │ │ ├── Register.vue │ │ │ ├── ResetPassword.vue │ │ │ └── VerifyEmail.vue │ │ ├── Cart │ │ │ └── Index.vue │ │ ├── Categories │ │ │ └── Show.vue │ │ ├── Checkout.vue │ │ ├── Dashboard.vue │ │ ├── Orders │ │ │ ├── Confirmation.vue │ │ │ └── Index.vue │ │ ├── Products │ │ │ ├── SearchResults.vue │ │ │ └── Show.vue │ │ ├── Profile │ │ │ ├── Edit.vue │ │ │ └── Partials │ │ │ │ ├── DeleteUserForm.vue │ │ │ │ ├── UpdatePasswordForm.vue │ │ │ │ └── UpdateProfileInformationForm.vue │ │ └── Welcome.vue │ ├── app.js │ ├── bootstrap.js │ └── helper.js └── views │ ├── app.blade.php │ ├── emails │ └── order │ │ ├── created.blade.php │ │ └── updated.blade.php │ └── welcome.blade.php ├── routes ├── api.php ├── auth.php ├── channels.php ├── console.php └── web.php ├── storage ├── app │ ├── .gitignore │ └── public │ │ └── .gitignore ├── debugbar │ └── .gitignore ├── framework │ ├── .gitignore │ ├── cache │ │ ├── .gitignore │ │ └── data │ │ │ └── .gitignore │ ├── sessions │ │ └── .gitignore │ ├── testing │ │ └── .gitignore │ └── views │ │ └── .gitignore └── logs │ └── .gitignore ├── tailwind.config.js ├── tests ├── CreatesApplication.php ├── Feature │ ├── Auth │ │ ├── AuthenticationTest.php │ │ ├── EmailVerificationTest.php │ │ ├── PasswordConfirmationTest.php │ │ ├── PasswordResetTest.php │ │ ├── PasswordUpdateTest.php │ │ └── RegistrationTest.php │ ├── ExampleTest.php │ └── ProfileTest.php ├── TestCase.php └── Unit │ └── ExampleTest.php └── vite.config.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 4 7 | indent_style = space 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | 14 | [*.{yml,yaml}] 15 | indent_size = 2 16 | 17 | [docker-compose.yml] 18 | indent_size = 4 19 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | APP_NAME=Laravel 2 | APP_ENV=local 3 | APP_KEY= 4 | APP_DEBUG=true 5 | APP_URL=http://localhost 6 | 7 | LOG_CHANNEL=stack 8 | LOG_DEPRECATIONS_CHANNEL=null 9 | LOG_LEVEL=debug 10 | 11 | DB_CONNECTION=mysql 12 | DB_HOST=127.0.0.1 13 | DB_PORT=3306 14 | DB_DATABASE=laravel_ecommerce_inertia 15 | DB_USERNAME=root 16 | DB_PASSWORD= 17 | 18 | BROADCAST_DRIVER=log 19 | CACHE_DRIVER=file 20 | FILESYSTEM_DISK=local 21 | QUEUE_CONNECTION=sync 22 | SESSION_DRIVER=file 23 | SESSION_LIFETIME=120 24 | 25 | MEMCACHED_HOST=127.0.0.1 26 | 27 | REDIS_HOST=127.0.0.1 28 | REDIS_PASSWORD=null 29 | REDIS_PORT=6379 30 | 31 | MAIL_MAILER=smtp 32 | MAIL_HOST=mailhog 33 | MAIL_PORT=1025 34 | MAIL_USERNAME=null 35 | MAIL_PASSWORD=null 36 | MAIL_ENCRYPTION=null 37 | MAIL_FROM_ADDRESS="hello@example.com" 38 | MAIL_FROM_NAME="${APP_NAME}" 39 | 40 | AWS_ACCESS_KEY_ID= 41 | AWS_SECRET_ACCESS_KEY= 42 | AWS_DEFAULT_REGION=us-east-1 43 | AWS_BUCKET= 44 | AWS_USE_PATH_STYLE_ENDPOINT=false 45 | 46 | PUSHER_APP_ID= 47 | PUSHER_APP_KEY= 48 | PUSHER_APP_SECRET= 49 | PUSHER_HOST= 50 | PUSHER_PORT=443 51 | PUSHER_SCHEME=https 52 | PUSHER_APP_CLUSTER=mt1 53 | 54 | VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}" 55 | VITE_PUSHER_HOST="${PUSHER_HOST}" 56 | VITE_PUSHER_PORT="${PUSHER_PORT}" 57 | VITE_PUSHER_SCHEME="${PUSHER_SCHEME}" 58 | VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" 59 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | *.blade.php diff=html 4 | *.css diff=css 5 | *.html diff=html 6 | *.md diff=markdown 7 | *.php diff=php 8 | 9 | /.github export-ignore 10 | CHANGELOG.md export-ignore 11 | .styleci.yml export-ignore 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Recommended template: Node.gitignore 2 | 3 | node_modules/ 4 | /public/build 5 | /vendor 6 | dist/ 7 | 8 | **/.DS_Store 9 | .DS_Store 10 | 11 | npm-debug.log 12 | yarn-error.log 13 | npm-debug.log 14 | yarn-error.log 15 | 16 | # Laravel 4 specific 17 | bootstrap/compiled.php 18 | app/storage/ 19 | 20 | # Laravel 5 & Lumen specific 21 | public/storage 22 | public/hot 23 | 24 | # Laravel 5 & Lumen specific with changed public path 25 | public_html/storage 26 | public_html/hot 27 | 28 | storage/*.key 29 | .env 30 | Homestead.yaml 31 | Homestead.json 32 | /.vagrant 33 | .phpunit.result.cache 34 | 35 | # End of https://mrkandreev.name/snippets/gitignore-generator/#Vuejs,Laravel 36 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/commandlinetools/schemas/frameworkDescriptionVersion1.1.4.xsd: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 14 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/Actions/GetCart.php: -------------------------------------------------------------------------------- 1 | with([ 15 | 'variations.media', 16 | 'variations.product:id,title', 17 | 'variations.stocks', 18 | 'variations.ancestorsAndSelf', 19 | ]) 20 | ->whereUuid($session->get(config('cart.session.key'))) 21 | ->first(); 22 | 23 | if ($instance) { 24 | // Populate variation media urls 25 | $this->populateVariationMediaUrls($instance->variations); 26 | 27 | // Populate Stock 28 | $this->loadStock($instance->variations); 29 | } 30 | 31 | return $instance; 32 | } 33 | 34 | /** 35 | * @param Collection $variations 36 | * @return void 37 | */ 38 | private function populateVariationMediaUrls(Collection $variations): void 39 | { 40 | $variations->each->getMediaUrls(); 41 | } 42 | 43 | /** 44 | * @param Collection $variations 45 | * @return void 46 | */ 47 | private function loadStock(Collection $variations): void 48 | { 49 | $variations->each->loadStock(); 50 | } 51 | } -------------------------------------------------------------------------------- /app/Actions/GetOrderVariations.php: -------------------------------------------------------------------------------- 1 | orders() 15 | ->with([ 16 | 'shippingType', 17 | 'variations.media', 18 | 'variations.product:id,title', 19 | 'variations.ancestorsAndSelf', 20 | ]) 21 | ->get() 22 | ->each(function (Order $order) { 23 | $order->variations?->each?->getMediaUrls(); 24 | }); 25 | } 26 | } -------------------------------------------------------------------------------- /app/Actions/Search.php: -------------------------------------------------------------------------------- 1 | get('search')) ?? '')->get(); 14 | } 15 | } -------------------------------------------------------------------------------- /app/Actions/ShowProduct.php: -------------------------------------------------------------------------------- 1 | loadVariationTree($product); 16 | 17 | // load product's variations stock 18 | $product->loadStock(); 19 | 20 | // prepare media urls 21 | $this->loadMedia($product); 22 | 23 | // Preload product on variations 24 | $this->preloadProductsOnVariation($product); 25 | 26 | return $product; 27 | } 28 | 29 | private function loadVariationTree(Product $product): void 30 | { 31 | $product->setRelation( 32 | 'variations', 33 | Variation::query() 34 | ->with('stocks') 35 | ->treeOf(fn($query) => $query->isRoot()->where('product_id', $product->id)) 36 | ->get() 37 | ->toTree() 38 | ); 39 | } 40 | 41 | private function loadMedia($product): void 42 | { 43 | // Load relationship 44 | // This way, we can load media to multiple product at once when needed 45 | $product->load('media'); 46 | 47 | // Do in-memory image generation 48 | $product->getMediaUrls(); 49 | } 50 | 51 | private function preloadProductsOnVariation($product): void 52 | { 53 | $product->variations->each->setRelation('product', $product); 54 | } 55 | } -------------------------------------------------------------------------------- /app/Cart/Contracts/CartInterface.php: -------------------------------------------------------------------------------- 1 | getAmount(); 39 | } 40 | 41 | return intval($value); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/Console/Commands/Search/SetupSearchFilters.php: -------------------------------------------------------------------------------- 1 | argument( 22 | key: 'index', 23 | ); 24 | 25 | $model = match ($index) { 26 | 'products' => Product::class, 27 | }; 28 | 29 | try { 30 | $this->info( 31 | string: "Updating filterable attributes for [$model] on index [$index]", 32 | ); 33 | 34 | $client->index( 35 | uid: $index, 36 | )->updateFilterableAttributes( 37 | filterableAttributes: $model::getSearchFilterAttributes(), 38 | ); 39 | } catch (Exception $exception) { 40 | $this->warn( 41 | string: $exception->getMessage(), 42 | ); 43 | 44 | return self::FAILURE; 45 | } 46 | return 0; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/Console/Kernel.php: -------------------------------------------------------------------------------- 1 | command('inspire')->hourly(); 19 | } 20 | 21 | /** 22 | * Register the commands for the application. 23 | * 24 | * @return void 25 | */ 26 | protected function commands() 27 | { 28 | $this->load(__DIR__.'/Commands'); 29 | 30 | require base_path('routes/console.php'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/Exceptions/Handler.php: -------------------------------------------------------------------------------- 1 | , \Psr\Log\LogLevel::*> 14 | */ 15 | protected $levels = [ 16 | // 17 | ]; 18 | 19 | /** 20 | * A list of the exception types that are not reported. 21 | * 22 | * @var array> 23 | */ 24 | protected $dontReport = [ 25 | // 26 | ]; 27 | 28 | /** 29 | * A list of the inputs that are never flashed to the session on validation exceptions. 30 | * 31 | * @var array 32 | */ 33 | protected $dontFlash = [ 34 | 'current_password', 35 | 'password', 36 | 'password_confirmation', 37 | ]; 38 | 39 | /** 40 | * Register the exception handling callbacks for the application. 41 | * 42 | * @return void 43 | */ 44 | public function register() 45 | { 46 | $this->reportable(function (Throwable $e) { 47 | // 48 | }); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/AuthenticatedSessionController.php: -------------------------------------------------------------------------------- 1 | Route::has('password.request'), 25 | 'status' => session('status'), 26 | ]); 27 | } 28 | 29 | /** 30 | * Handle an incoming authentication request. 31 | * 32 | * @param \App\Http\Requests\Auth\LoginRequest $request 33 | * @return \Illuminate\Http\RedirectResponse 34 | */ 35 | public function store(LoginRequest $request, CartInterface $cart) 36 | { 37 | $request->authenticate(); 38 | 39 | // regenerating the session by default doesn't delete the session data 40 | // only the ID changes to protect against malicious attacks 41 | $request->session()->regenerate(); 42 | 43 | $cart->associate($request->user()); 44 | 45 | return redirect()->intended(RouteServiceProvider::HOME); 46 | } 47 | 48 | /** 49 | * Destroy an authenticated session. 50 | * 51 | * @param \Illuminate\Http\Request $request 52 | * @return \Illuminate\Http\RedirectResponse 53 | */ 54 | public function destroy(Request $request) 55 | { 56 | Auth::guard('web')->logout(); 57 | 58 | $request->session()->invalidate(); 59 | 60 | $request->session()->regenerateToken(); 61 | 62 | return redirect('/'); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/ConfirmablePasswordController.php: -------------------------------------------------------------------------------- 1 | validate([ 33 | 'email' => $request->user()->email, 34 | 'password' => $request->password, 35 | ])) { 36 | throw ValidationException::withMessages([ 37 | 'password' => __('auth.password'), 38 | ]); 39 | } 40 | 41 | $request->session()->put('auth.password_confirmed_at', time()); 42 | 43 | return redirect()->intended(RouteServiceProvider::HOME); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/EmailVerificationNotificationController.php: -------------------------------------------------------------------------------- 1 | user()->hasVerifiedEmail()) { 20 | return redirect()->intended(RouteServiceProvider::HOME); 21 | } 22 | 23 | $request->user()->sendEmailVerificationNotification(); 24 | 25 | return back()->with('status', 'verification-link-sent'); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/EmailVerificationPromptController.php: -------------------------------------------------------------------------------- 1 | user()->hasVerifiedEmail() 21 | ? redirect()->intended(RouteServiceProvider::HOME) 22 | : Inertia::render('Auth/VerifyEmail', ['status' => session('status')]); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/PasswordController.php: -------------------------------------------------------------------------------- 1 | validate([ 21 | 'current_password' => ['required', 'current_password'], 22 | 'password' => ['required', Password::defaults(), 'confirmed'], 23 | ]); 24 | 25 | $request->user()->update([ 26 | 'password' => Hash::make($validated['password']), 27 | ]); 28 | 29 | return back(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/PasswordResetLinkController.php: -------------------------------------------------------------------------------- 1 | session('status'), 22 | ]); 23 | } 24 | 25 | /** 26 | * Handle an incoming password reset link request. 27 | * 28 | * @param \Illuminate\Http\Request $request 29 | * @return \Illuminate\Http\RedirectResponse 30 | * 31 | * @throws \Illuminate\Validation\ValidationException 32 | */ 33 | public function store(Request $request) 34 | { 35 | $request->validate([ 36 | 'email' => 'required|email', 37 | ]); 38 | 39 | // We will send the password reset link to this user. Once we have attempted 40 | // to send the link, we will examine the response then see the message we 41 | // need to show to the user. Finally, we'll send out a proper response. 42 | $status = Password::sendResetLink( 43 | $request->only('email') 44 | ); 45 | 46 | if ($status == Password::RESET_LINK_SENT) { 47 | return back()->with('status', __($status)); 48 | } 49 | 50 | throw ValidationException::withMessages([ 51 | 'email' => [trans($status)], 52 | ]); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/RegisteredUserController.php: -------------------------------------------------------------------------------- 1 | validate([ 38 | 'name' => 'required|string|max:255', 39 | 'email' => 'required|string|email|max:255|unique:'.User::class, 40 | 'password' => ['required', 'confirmed', Rules\Password::defaults()], 41 | ]); 42 | 43 | $user = User::create([ 44 | 'name' => $request->name, 45 | 'email' => $request->email, 46 | 'password' => Hash::make($request->password), 47 | ]); 48 | 49 | event(new Registered($user)); 50 | 51 | Auth::login($user); 52 | 53 | return redirect(RouteServiceProvider::HOME); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/VerifyEmailController.php: -------------------------------------------------------------------------------- 1 | user()->hasVerifiedEmail()) { 21 | return redirect()->intended(RouteServiceProvider::HOME.'?verified=1'); 22 | } 23 | 24 | if ($request->user()->markEmailAsVerified()) { 25 | event(new Verified($request->user())); 26 | } 27 | 28 | return redirect()->intended(RouteServiceProvider::HOME.'?verified=1'); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/Http/Controllers/CartController.php: -------------------------------------------------------------------------------- 1 | verifyAvailableQuantities(); 17 | } catch (QuantityNoLongerAvailableException) { 18 | // When returning Inertia view 19 | session()->now('notification', [ 20 | 'title' => 'Some items or quantities in your cart have become unavailable.', 21 | 'color' => 'gray', 22 | ]); 23 | 24 | $cart->syncAvailableQuantities(); 25 | } 26 | 27 | return Inertia::render('Cart/Index'); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/Http/Controllers/CartVariationController.php: -------------------------------------------------------------------------------- 1 | findOrFail($request->variation); 25 | 26 | // Add the Variation 27 | $cart->add($variation, $request->get('quantity', 1)); 28 | 29 | // Prepare a success notification message 30 | $request->success($variation); 31 | } 32 | catch (Exception $ex) 33 | { 34 | Log::error($ex->getMessage()); 35 | } 36 | 37 | return redirect()->back()->withNotification($request->notification); 38 | } 39 | 40 | /** 41 | * Update the specified resource in storage. 42 | * 43 | * @param CartInterface $cart 44 | * @param PatchCartVariationRequest $request 45 | * @param Variation $variation 46 | * @return RedirectResponse 47 | */ 48 | public function update(PatchCartVariationRequest $request, Variation $variation, CartInterface $cart): RedirectResponse 49 | { 50 | // Change the variation quantity 51 | $cart->changeQuantity($variation, $request->get('quantity', 1)); 52 | 53 | // Prepare a success notification message 54 | $request->success(); 55 | 56 | return redirect()->back()->withNotification($request->notification); 57 | } 58 | 59 | /** 60 | * @param Variation $variation 61 | * @return RedirectResponse 62 | */ 63 | public function destroy(CartInterface $cart, Variation $variation): RedirectResponse 64 | { 65 | $cart->remove($variation); 66 | 67 | $notification = [ 68 | 'title' => "Item removed", 69 | 'message' => 'Your item was successfully removed!', 70 | 'color' => 'green', 71 | ]; 72 | 73 | return redirect()->back()->withNotification($notification); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /app/Http/Controllers/CategoryShowController.php: -------------------------------------------------------------------------------- 1 | execute($request, $category); 24 | 25 | return Inertia::render('Categories/Show', [ 26 | 'category' => new CategoryResource($search['category']), 27 | 'products' => ProductResource::collection($search['products']), 28 | 'filters' => new FilterResource($search['filters']), 29 | 'maxPrice' => $search['maxPrice'], 30 | ]); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/Http/Controllers/CheckoutController.php: -------------------------------------------------------------------------------- 1 | middleware(RedirectIfCartEmpty::class); 18 | } 19 | 20 | public function __invoke(Request $request): Response 21 | { 22 | return Inertia::render('Checkout',[ 23 | 'shippingTypes' => ShippingTypeResource::collection(ShippingType::orderBy('price', 'asc')->get()), 24 | 'shippingAddresses' => ShippingAddressResource::collection(auth()->user()->shippingAddresses ?? []), 25 | ]); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/Http/Controllers/Controller.php: -------------------------------------------------------------------------------- 1 | CategoryResource::collection(Category::tree()->get()->toTree()), 16 | ]); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /app/Http/Controllers/OrderConfirmationIndexController.php: -------------------------------------------------------------------------------- 1 | render('Orders/Index', [ 14 | 'orders' => OrderResource::collection($getOrderVariations->execute(auth()->user())), 15 | ]); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/Http/Controllers/PaymentIntentController.php: -------------------------------------------------------------------------------- 1 | hasPaymentIntent()) { 22 | $paymentIntent = app('stripe')->paymentIntents->create([ 23 | 'amount' => (int)$request->total, // cents 24 | 'currency' => config('money.defaultCurrency'), 25 | 'setup_future_usage' => 'on_session', // on-time payment 26 | 'metadata' => [ 27 | 'user_id' => $request->user()?->id, // can be used later in Webhooks 28 | ], 29 | 'payment_method_types' => ['card'], 30 | ]); 31 | 32 | // store payment intent id on cart 33 | $cart->updatePaymentIntentId($paymentIntent->id); 34 | } else { 35 | $paymentIntent = app('stripe')->paymentIntents->retrieve($cart->getPaymentIntentId()); 36 | 37 | // update only pending payment intent 38 | if ($paymentIntent->status !== 'succeeded') { 39 | app('stripe')->paymentIntents->update($cart->getPaymentIntentId(), [ 40 | 'amount' => (int)$request->total, 41 | ]); 42 | 43 | $paymentIntent->amount = (int)$request->total; 44 | } 45 | } 46 | 47 | return PaymentIntentResource::make($paymentIntent); 48 | } 49 | } -------------------------------------------------------------------------------- /app/Http/Controllers/ProductShowController.php: -------------------------------------------------------------------------------- 1 | $showProduct->execute($product)->toResource(), 16 | ]); 17 | } 18 | } -------------------------------------------------------------------------------- /app/Http/Controllers/ProfileController.php: -------------------------------------------------------------------------------- 1 | $request->user() instanceof MustVerifyEmail, 24 | 'status' => session('status'), 25 | ]); 26 | } 27 | 28 | /** 29 | * Update the user's profile information. 30 | * 31 | * @param \App\Http\Requests\ProfileUpdateRequest $request 32 | * @return \Illuminate\Http\RedirectResponse 33 | */ 34 | public function update(ProfileUpdateRequest $request) 35 | { 36 | $request->user()->fill($request->validated()); 37 | 38 | if ($request->user()->isDirty('email')) { 39 | $request->user()->email_verified_at = null; 40 | } 41 | 42 | $request->user()->save(); 43 | 44 | return Redirect::route('profile.edit'); 45 | } 46 | 47 | /** 48 | * Delete the user's account. 49 | * 50 | * @param \Illuminate\Http\Request $request 51 | * @return \Illuminate\Http\RedirectResponse 52 | */ 53 | public function destroy(Request $request) 54 | { 55 | $request->validate([ 56 | 'password' => ['required', 'current-password'], 57 | ]); 58 | 59 | $user = $request->user(); 60 | 61 | Auth::logout(); 62 | 63 | $user->delete(); 64 | 65 | $request->session()->invalidate(); 66 | $request->session()->regenerateToken(); 67 | 68 | return Redirect::to('/'); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /app/Http/Controllers/SearchController.php: -------------------------------------------------------------------------------- 1 | ProductResource::collection($search->execute($request)), 17 | ]); 18 | } 19 | } -------------------------------------------------------------------------------- /app/Http/Middleware/Authenticate.php: -------------------------------------------------------------------------------- 1 | expectsJson()) { 18 | return route('login'); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/Http/Middleware/CartMiddleware.php: -------------------------------------------------------------------------------- 1 | cart->exists()) 18 | { 19 | $this->cart->create($request->user()); 20 | } 21 | 22 | return $next($request); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/Http/Middleware/EncryptCookies.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | protected $except = [ 15 | // 16 | ]; 17 | } 18 | -------------------------------------------------------------------------------- /app/Http/Middleware/HandleInertiaRequests.php: -------------------------------------------------------------------------------- 1 | [ 44 | 'user' => $request->user(), 45 | ], 46 | 'cart' => fn () => $this->cart->toResource(), 47 | 'money' => [ 48 | 'locale' => config('money.locale'), 49 | 'currency' => config('money.defaultCurrency'), 50 | ], 51 | 'flash' => [ 52 | 'notification' => fn () => $request->session()->get('notification') 53 | ], 54 | 'ziggy' => function () use ($request) { 55 | return array_merge((new Ziggy())->toArray(), [ 56 | 'location' => $request->url(), 57 | ]); 58 | }, 59 | ]); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /app/Http/Middleware/PreventRequestsDuringMaintenance.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | protected $except = [ 15 | // 16 | ]; 17 | } 18 | -------------------------------------------------------------------------------- /app/Http/Middleware/RedirectIfAuthenticated.php: -------------------------------------------------------------------------------- 1 | check()) { 26 | return redirect(RouteServiceProvider::HOME); 27 | } 28 | } 29 | 30 | return $next($request); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/Http/Middleware/RedirectIfCartEmpty.php: -------------------------------------------------------------------------------- 1 | cart->isEmpty()) { 25 | return to_route('cart.index'); 26 | } 27 | return $next($request); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/Http/Middleware/TrimStrings.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | protected $except = [ 15 | 'current_password', 16 | 'password', 17 | 'password_confirmation', 18 | ]; 19 | } 20 | -------------------------------------------------------------------------------- /app/Http/Middleware/TrustHosts.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | public function hosts() 15 | { 16 | return [ 17 | $this->allSubdomainsOfApplicationUrl(), 18 | ]; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/Http/Middleware/TrustProxies.php: -------------------------------------------------------------------------------- 1 | |string|null 14 | */ 15 | protected $proxies; 16 | 17 | /** 18 | * The headers that should be used to detect proxies. 19 | * 20 | * @var int 21 | */ 22 | protected $headers = 23 | Request::HEADER_X_FORWARDED_FOR | 24 | Request::HEADER_X_FORWARDED_HOST | 25 | Request::HEADER_X_FORWARDED_PORT | 26 | Request::HEADER_X_FORWARDED_PROTO | 27 | Request::HEADER_X_FORWARDED_AWS_ELB; 28 | } 29 | -------------------------------------------------------------------------------- /app/Http/Middleware/ValidateSignature.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | protected $except = [ 15 | // 'fbclid', 16 | // 'utm_campaign', 17 | // 'utm_content', 18 | // 'utm_medium', 19 | // 'utm_source', 20 | // 'utm_term', 21 | ]; 22 | } 23 | -------------------------------------------------------------------------------- /app/Http/Middleware/VerifyCsrfToken.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | protected $except = [ 15 | // 16 | ]; 17 | } 18 | -------------------------------------------------------------------------------- /app/Http/Requests/Auth/LoginRequest.php: -------------------------------------------------------------------------------- 1 | ['required', 'string', 'email'], 33 | 'password' => ['required', 'string'], 34 | ]; 35 | } 36 | 37 | /** 38 | * Attempt to authenticate the request's credentials. 39 | * 40 | * @return void 41 | * 42 | * @throws \Illuminate\Validation\ValidationException 43 | */ 44 | public function authenticate() 45 | { 46 | $this->ensureIsNotRateLimited(); 47 | 48 | if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) { 49 | RateLimiter::hit($this->throttleKey()); 50 | 51 | throw ValidationException::withMessages([ 52 | 'email' => trans('auth.failed'), 53 | ]); 54 | } 55 | 56 | RateLimiter::clear($this->throttleKey()); 57 | } 58 | 59 | /** 60 | * Ensure the login request is not rate limited. 61 | * 62 | * @return void 63 | * 64 | * @throws \Illuminate\Validation\ValidationException 65 | */ 66 | public function ensureIsNotRateLimited() 67 | { 68 | if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) { 69 | return; 70 | } 71 | 72 | event(new Lockout($this)); 73 | 74 | $seconds = RateLimiter::availableIn($this->throttleKey()); 75 | 76 | throw ValidationException::withMessages([ 77 | 'email' => trans('auth.throttle', [ 78 | 'seconds' => $seconds, 79 | 'minutes' => ceil($seconds / 60), 80 | ]), 81 | ]); 82 | } 83 | 84 | /** 85 | * Get the rate limiting throttle key for the request. 86 | * 87 | * @return string 88 | */ 89 | public function throttleKey() 90 | { 91 | return Str::transliterate(Str::lower($this->input('email')).'|'.$this->ip()); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /app/Http/Requests/PatchCartVariationRequest.php: -------------------------------------------------------------------------------- 1 | "Couldn't update quantity", 12 | 'message' => 'Your item was not updated in the cart!', 13 | 'color' => 'red', 14 | ]; 15 | 16 | public function success(Variation $variation = null) 17 | { 18 | $this->notification = [ 19 | 'title' => 'Quantity updated', 20 | 'message' => 'Your cart has been successfully updated! ', 21 | 'color' => 'green', 22 | ]; 23 | } 24 | 25 | public function authorize(): bool 26 | { 27 | return true; 28 | } 29 | 30 | public function rules(): array 31 | { 32 | return [ 33 | 'variation' => ['required', 'int',], 34 | 'quantity' => ['sometimes', 'required', 'integer',], 35 | ]; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/Http/Requests/PaymentIntentRequest.php: -------------------------------------------------------------------------------- 1 | 23 | */ 24 | public function rules(): array 25 | { 26 | return [ 27 | 'total' => ['required', 'integer'], 28 | ]; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/Http/Requests/ProfileUpdateRequest.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | public function rules() 17 | { 18 | return [ 19 | 'name' => ['string', 'max:255'], 20 | 'email' => ['email', 'max:255', Rule::unique(User::class)->ignore($this->user()->id)], 21 | ]; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/Http/Requests/StoreCartVariationRequest.php: -------------------------------------------------------------------------------- 1 | "Couldn't add to cart", 12 | 'message' => 'Your item was not added to cart!', 13 | 'color' => 'red', 14 | ]; 15 | 16 | public function success(Variation $variation = null) 17 | { 18 | $this->notification = [ 19 | 'title' => "({$variation?->product?->title}) added to cart", 20 | 'message' => 'Your item has been successfully added! ', 21 | 'color' => 'green', 22 | ]; 23 | } 24 | 25 | public function authorize(): bool 26 | { 27 | return true; 28 | } 29 | 30 | public function rules(): array 31 | { 32 | return [ 33 | 'variation' => ['required', 'integer',], 34 | 'quantity' => ['sometimes', 'required', 'integer'], 35 | ]; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/Http/Requests/StoreOrderRequest.php: -------------------------------------------------------------------------------- 1 | 24 | */ 25 | public function rules(): array 26 | { 27 | return [ 28 | 'shipping.address' => ['required', 'max:255'] , 29 | 'shipping.city' => ['required', 'max:255'], 30 | 'shipping.postCode' => ['required', 'max:255'], 31 | 'shippingType' => ['required'], 32 | ]; 33 | } 34 | 35 | public function messages(): array 36 | { 37 | return [ 38 | 'shipping.address.required' => 'The shipping address is required.', 39 | 'shipping.address.max' => 'The shipping address must not be greater than 255 characters.', 40 | 'shipping.city.required' => 'The shipping city is required.', 41 | 'shipping.city.max' => 'The shipping city must not be greater than 255 characters.', 42 | 'shipping.postCode.required' => 'The shipping postcode is required.', 43 | 'shipping.postCode.max' => 'The shipping postcode must not be greater than 255 characters.', 44 | 'shippingTYpe.required' => 'The shipping type is required.', 45 | ]; 46 | } 47 | 48 | public function withValidator(Validator $validator) 49 | { 50 | $validator->sometimes( 51 | attribute: 'email', 52 | rules: ['required', 'email', 'max:255', 'unique:users,email'], 53 | callback: fn ($input) => auth()->guest(), 54 | ); 55 | } 56 | 57 | protected function prepareForValidation() 58 | { 59 | $this->merge(['shipping' => [...$this->shipping, 'postcode' =>$this->shipping['postCode']]]); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /app/Http/Resources/CartResource.php: -------------------------------------------------------------------------------- 1 | items(); 19 | 20 | return [ 21 | 'items' => VariationResource::collection($items), 22 | 'count' => $items->count() ?? 0, 23 | 'subTotal' => $this->subTotal(), 24 | ]; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/Http/Resources/CategoryResource.php: -------------------------------------------------------------------------------- 1 | CategoryResource::collection($this->whenLoaded('ancestors')), 19 | 'children' => CategoryResource::collection($this->whenLoaded('children')), 20 | 'depth' => $this->depth, 21 | 'products' => ProductResource::collection($this->whenLoaded('products')), 22 | 'slug' => $this->slug, 23 | 'title' => $this->title, 24 | ]; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/Http/Resources/FilterResource.php: -------------------------------------------------------------------------------- 1 | resource) 22 | ->mapWithKeys(function ($filter, $key) { 23 | if (!is_array($filter)) { 24 | return $filter; 25 | } 26 | 27 | // Make filter array keys as string 28 | $filter = collect($filter)->mapWithKeys(function ($filterValue, $filterKey) use ($key) { 29 | // A hacky way to convert int-keys to string-keys 30 | // On the frontend, I will replace [ and ] with empty string for display 31 | return ['[' . $filterKey . ']' => $filterValue]; 32 | }); 33 | 34 | return [$key => $filter]; 35 | })->toArray(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/Http/Resources/OrderResource.php: -------------------------------------------------------------------------------- 1 | $this->id, 20 | 'subTotal' => $this->subtotal, 21 | 'createdAt' => $this->created_at->toDateTimeString(), 22 | 'shippingType' => ShippingTypeResource::make($this->whenLoaded('shippingType')), 23 | 'variations' => VariationResource::collection($this->whenLoaded('variations')), 24 | 'status' => $this->status(), 25 | ]; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/Http/Resources/PaymentIntentResource.php: -------------------------------------------------------------------------------- 1 | $this->id, 20 | 'clientSecret' => $this->client_secret, 21 | 'amount' => $this->amount, 22 | ]; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/Http/Resources/ProductResource.php: -------------------------------------------------------------------------------- 1 | $this->id, 19 | 'description' => $this->description, 20 | 'liveAt' => $this->live_at, 21 | 'medias' => $this->whenLoaded('media') ? $this->medias : [], 22 | 'price' => $this->price, 23 | 'slug' => $this->slug, 24 | 'title' => $this->title, 25 | 'variations' => VariationResource::collection($this->whenLoaded('variations')), 26 | ]; 27 | } 28 | } -------------------------------------------------------------------------------- /app/Http/Resources/ShippingAddressResource.php: -------------------------------------------------------------------------------- 1 | $this->id, 22 | 'address' => $this->address, 23 | 'city' => $this->city, 24 | 'postCode' => $this->postcode, 25 | ]; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/Http/Resources/ShippingTypeResource.php: -------------------------------------------------------------------------------- 1 | $this->id, 19 | 'title' => $this->title, 20 | 'price' => $this->price, 21 | ]; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/Http/Resources/VariationResource.php: -------------------------------------------------------------------------------- 1 | $this->id, 21 | 'displayName' => $this->display_name, 22 | 'medias' => $this->whenLoaded('media') ? $this->medias : [], 23 | 'order' => $this->order, 24 | 'parentId' => $this->parent_id, 25 | 'price' => $this->price, 26 | 'productId' => $this->product_id, 27 | 'productTitle' => $this->relationLoaded('product') ? $this->product->title : '', 28 | 'sku' => $this->sku, 29 | 'stockFigures' => $this->stockFigures ?? [], 30 | 'title' => $this->title, 31 | 'type' => $this->type, 32 | 'quantity' => $this->relationLoaded('pivot') ? $this->pivot->quantity : 0, 33 | 'ancestorsAndSelf' => VariationResource::collection($this->whenLoaded('ancestorsAndSelf')), 34 | 'children' => VariationResource::collection($this->whenLoaded('children')), 35 | ]; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/Listeners/AttachOrders.php: -------------------------------------------------------------------------------- 1 | whereEmail($event->user->email) 33 | ->get() 34 | ->each(function (Order $order) use ($event) { 35 | $order 36 | ->user() 37 | ->associate($event->user) 38 | ->save(); 39 | }); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/Mail/OrderCreated.php: -------------------------------------------------------------------------------- 1 | uuid = (string) Str::uuid(); 26 | }); 27 | } 28 | 29 | public function user(): BelongsTo 30 | { 31 | return $this->belongsTo(User::class); 32 | } 33 | 34 | public function variations(): BelongsToMany 35 | { 36 | return $this->belongsToMany(Variation::class) 37 | ->withPivot('quantity') 38 | ->orderBy('id'); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/Models/Category.php: -------------------------------------------------------------------------------- 1 | belongsToMany(Product::class); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/Models/Order.php: -------------------------------------------------------------------------------- 1 | 'Order Placed', 33 | 'packaged_at' => 'Order Packaged', 34 | 'shipped_at' => 'Order Shipped', 35 | ]; 36 | 37 | protected function getMoneyAttribute(): string 38 | { 39 | return 'subtotal'; 40 | } 41 | 42 | public function user(): BelongsTo 43 | { 44 | return $this->belongsTo(User::class); 45 | } 46 | 47 | public function shippingAddress(): BelongsTo 48 | { 49 | return $this->belongsTo(ShippingAddress::class); 50 | } 51 | 52 | public function shippingType(): BelongsTo 53 | { 54 | return $this->belongsTo(ShippingType::class); 55 | } 56 | 57 | public function variations(): BelongsToMany 58 | { 59 | return $this->belongsToMany(Variation::class) 60 | ->withPivot(['quantity']) 61 | ->withTimestamps(); 62 | } 63 | 64 | public function status() 65 | { 66 | return collect($this->statuses) 67 | ->last(fn ($status, $key) => filled($this->{$key})); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /app/Models/Scopes/LiveScope.php: -------------------------------------------------------------------------------- 1 | whereNotNull('live_at'); // not null is live 14 | } 15 | } -------------------------------------------------------------------------------- /app/Models/ShippingAddress.php: -------------------------------------------------------------------------------- 1 | belongsTo(User::class); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/Models/ShippingType.php: -------------------------------------------------------------------------------- 1 | 22 | */ 23 | protected $fillable = [ 24 | 'name', 25 | 'email', 26 | 'password', 27 | ]; 28 | 29 | /** 30 | * The attributes that should be hidden for serialization. 31 | * 32 | * @var array 33 | */ 34 | protected $hidden = [ 35 | 'password', 36 | 'remember_token', 37 | ]; 38 | 39 | /** 40 | * The attributes that should be cast. 41 | * 42 | * @var array 43 | */ 44 | protected $casts = [ 45 | 'email_verified_at' => 'datetime', 46 | ]; 47 | 48 | public function shippingAddresses(): HasMany 49 | { 50 | return $this->hasMany(ShippingAddress::class); 51 | } 52 | 53 | public function orders(): HasMany 54 | { 55 | return $this->hasMany(Order::class)->latest(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/Models/Variation.php: -------------------------------------------------------------------------------- 1 | belongsTo(Product::class); 44 | } 45 | 46 | public function stocks(): HasMany 47 | { 48 | return $this->hasMany(Stock::class); 49 | } 50 | 51 | public function stockCount() 52 | { 53 | return $this->stocks->sum('amount'); 54 | } 55 | 56 | public function registerMediaConversions(Media $media = null): void 57 | { 58 | $this->addMediaConversion('thumb200x200') 59 | ->fit(Manipulations::FIT_CROP, 200, 200); 60 | } 61 | 62 | public function registerMediaCollections(): void 63 | { 64 | $this 65 | ->addMediaCollection('default') 66 | ->useFallbackUrl(url('/images/no_image_available.jpg')); 67 | } 68 | 69 | /** 70 | * Get the formatted title. 71 | * 72 | * @return \Illuminate\Database\Eloquent\Casts\Attribute 73 | */ 74 | protected function displayName(): Attribute 75 | { 76 | return Attribute::make( 77 | get: fn () => Str::title($this->type), 78 | ); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /app/Observers/OrderObserver.php: -------------------------------------------------------------------------------- 1 | placed_at = now(); 15 | $order->uuid = (string)Str::uuid(); 16 | } 17 | 18 | public function updating (Order $order): void 19 | { 20 | // construct original order from original columns 21 | $originalOrder = new Order( 22 | collect($order->getOriginal()) 23 | ->only($order->statuses) 24 | ->toArray() 25 | ); 26 | 27 | // getDirty(): Get the attributes that have been changed since the last sync. 28 | $filledStatuses = collect($order->getDirty()) 29 | ->only(array_keys($order->statuses)) // only columns we want 30 | ->filter(fn ($status) => filled($status)); // only those filled with values not set to null to get the real columns updated 31 | 32 | // If there is a change in the status in the right order, then send email 33 | // Placed At -> Packaged At -> Shipped At 34 | if ($originalOrder->status() !== $order->status() && $filledStatuses->count() > 0) 35 | { 36 | Mail::to($order->user)->send(new OrderStatusUpdated($order)); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/Providers/AppServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->isLocal()) { 21 | $this->app->register(IdeHelperServiceProvider::class); 22 | } 23 | } 24 | 25 | /** 26 | * Bootstrap any application services. 27 | * 28 | * @return void 29 | */ 30 | public function boot() 31 | { 32 | Collection::macro('recursive', function () { 33 | return $this->map( function($value) { 34 | if (is_array($value) || is_object($value)) 35 | { 36 | return collect($value)->recursive(); 37 | } 38 | 39 | return $value; 40 | }); 41 | }); 42 | 43 | Order::observe(OrderObserver::class); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/Providers/AuthServiceProvider.php: -------------------------------------------------------------------------------- 1 | 14 | */ 15 | protected $policies = [ 16 | // 'App\Models\Model' => 'App\Policies\ModelPolicy', 17 | ]; 18 | 19 | /** 20 | * Register any authentication / authorization services. 21 | * 22 | * @return void 23 | */ 24 | public function boot() 25 | { 26 | $this->registerPolicies(); 27 | 28 | // 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/Providers/BroadcastServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->singleton(CartInterface::class, fn () => new Cart(session(), $this->app->make(GetCart::class))); 21 | } 22 | 23 | /** 24 | * Bootstrap services. 25 | * 26 | * @return void 27 | */ 28 | public function boot() 29 | { 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/Providers/EventServiceProvider.php: -------------------------------------------------------------------------------- 1 | > 16 | */ 17 | protected $listen = [ 18 | Registered::class => [ 19 | SendEmailVerificationNotification::class, 20 | AttachOrders::class, 21 | ], 22 | ]; 23 | 24 | /** 25 | * Register any events for your application. 26 | * 27 | * @return void 28 | */ 29 | public function boot() 30 | { 31 | // 32 | } 33 | 34 | /** 35 | * Determine if events and listeners should be automatically discovered. 36 | * 37 | * @return bool 38 | */ 39 | public function shouldDiscoverEvents() 40 | { 41 | return false; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/Providers/RouteServiceProvider.php: -------------------------------------------------------------------------------- 1 | configureRateLimiting(); 30 | 31 | $this->routes(function () { 32 | Route::middleware('api') 33 | ->prefix('api') 34 | ->group(base_path('routes/api.php')); 35 | 36 | Route::middleware('web') 37 | ->group(base_path('routes/web.php')); 38 | }); 39 | } 40 | 41 | /** 42 | * Configure the rate limiters for the application. 43 | * 44 | * @return void 45 | */ 46 | protected function configureRateLimiting() 47 | { 48 | RateLimiter::for('api', function (Request $request) { 49 | return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip()); 50 | }); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/Providers/StripeServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->singleton('stripe', function () { 18 | return new StripeClient(config('stripe.secret')); 19 | }); 20 | } 21 | 22 | /** 23 | * Bootstrap services. 24 | * 25 | * @return void 26 | */ 27 | public function boot(): void 28 | { 29 | // 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/Traits/HasFormattedPrice.php: -------------------------------------------------------------------------------- 1 | append($this->getMoneyAttribute()); 15 | 16 | // Add an accessor dynamically 17 | $this->casts = array_merge($this->casts, [ 18 | $this->getMoneyAttribute() => MoneyAttribute::class, 19 | ]); 20 | } 21 | } -------------------------------------------------------------------------------- /app/Traits/HasImages.php: -------------------------------------------------------------------------------- 1 | relationLoaded('media')) 19 | { 20 | return; 21 | } 22 | 23 | // initialize the media file 24 | $this->medias = collect([]); 25 | 26 | $this->media->each(function ($media) { 27 | $mediaFile = new MediaFile( 28 | originalImage: $media->getUrl(), 29 | thumbnails: $media->getGeneratedConversions()->keys()->map(function ($conversion) use ($media) { 30 | return $media->getUrl($conversion); 31 | })->all() 32 | ); 33 | 34 | $this->medias->push($mediaFile); 35 | }); 36 | 37 | // Set a default image when no images are found 38 | if ($this->medias->isEmpty()) { 39 | $mediaFile = new MediaFile( 40 | // it generates a default image implicitly 41 | originalImage: $this->getFirstMediaUrl(), 42 | ); 43 | 44 | $this->medias->push($mediaFile); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /app/Traits/HasStock.php: -------------------------------------------------------------------------------- 1 | getStock($this); 12 | } 13 | 14 | private function getStock (Variation $variation): int 15 | { 16 | $stockFigures = StockFigures::make(); 17 | 18 | if ($variation->relationLoaded('stocks')) 19 | { 20 | $stockFigures->stockCount = $this->calculateSelfStock($variation); 21 | 22 | $this->calculateStockState($stockFigures); 23 | $variation['stockFigures'] = $stockFigures; 24 | } 25 | 26 | if ($variation->relationLoaded('children')) { 27 | foreach ($variation->children as $childVariation) 28 | { 29 | $stockFigures->stockCount += $this->getStock($childVariation); 30 | 31 | $this->calculateStockState($stockFigures); 32 | $variation['stockFigures'] = $stockFigures; 33 | } 34 | } 35 | 36 | return $stockFigures->stockCount; 37 | } 38 | 39 | private function calculateSelfStock(Variation $variation): int 40 | { 41 | return array_reduce($variation->stocks->toArray(), function ($carry, $item) { 42 | return $carry + $item['amount']; 43 | }, 0); 44 | } 45 | 46 | private function minStock(): int 47 | { 48 | return intVal(config('services.shop.lowStock')); 49 | } 50 | 51 | private function calculateStockState($stockFigures): void 52 | { 53 | $stockFigures->inStock = $stockFigures->stockCount > 0; 54 | $stockFigures->outOfStock = $stockFigures->stockCount <= 0; 55 | $stockFigures->lowStock = !$stockFigures->outOfStock && $stockFigures->stockCount < $this->minStock(); 56 | } 57 | } -------------------------------------------------------------------------------- /app/Traits/MediaFile.php: -------------------------------------------------------------------------------- 1 | make(Illuminate\Contracts\Console\Kernel::class); 34 | 35 | $status = $kernel->handle( 36 | $input = new Symfony\Component\Console\Input\ArgvInput, 37 | new Symfony\Component\Console\Output\ConsoleOutput 38 | ); 39 | 40 | /* 41 | |-------------------------------------------------------------------------- 42 | | Shutdown The Application 43 | |-------------------------------------------------------------------------- 44 | | 45 | | Once Artisan has finished running, we will fire off the shutdown events 46 | | so that any final work may be done by the application before we shut 47 | | down the process. This is the last thing to happen to the request. 48 | | 49 | */ 50 | 51 | $kernel->terminate($input, $status); 52 | 53 | exit($status); 54 | -------------------------------------------------------------------------------- /bootstrap/app.php: -------------------------------------------------------------------------------- 1 | singleton( 30 | Illuminate\Contracts\Http\Kernel::class, 31 | App\Http\Kernel::class 32 | ); 33 | 34 | $app->singleton( 35 | Illuminate\Contracts\Console\Kernel::class, 36 | App\Console\Kernel::class 37 | ); 38 | 39 | $app->singleton( 40 | Illuminate\Contracts\Debug\ExceptionHandler::class, 41 | App\Exceptions\Handler::class 42 | ); 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Return The Application 47 | |-------------------------------------------------------------------------- 48 | | 49 | | This script returns the application instance. The instance is given to 50 | | the calling script so we can separate the building of the instances 51 | | from the actual running of the application and sending responses. 52 | | 53 | */ 54 | 55 | return $app; 56 | -------------------------------------------------------------------------------- /bootstrap/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /config/broadcasting.php: -------------------------------------------------------------------------------- 1 | env('BROADCAST_DRIVER', 'null'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Broadcast Connections 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may define all of the broadcast connections that will be used 26 | | to broadcast events to other systems or over websockets. Samples of 27 | | each available type of connection are provided inside this array. 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'pusher' => [ 34 | 'driver' => 'pusher', 35 | 'key' => env('PUSHER_APP_KEY'), 36 | 'secret' => env('PUSHER_APP_SECRET'), 37 | 'app_id' => env('PUSHER_APP_ID'), 38 | 'options' => [ 39 | 'host' => env('PUSHER_HOST') ?: 'api-'.env('PUSHER_APP_CLUSTER', 'mt1').'.pusher.com', 40 | 'port' => env('PUSHER_PORT', 443), 41 | 'scheme' => env('PUSHER_SCHEME', 'https'), 42 | 'encrypted' => true, 43 | 'useTLS' => env('PUSHER_SCHEME', 'https') === 'https', 44 | ], 45 | 'client_options' => [ 46 | // Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html 47 | ], 48 | ], 49 | 50 | 'ably' => [ 51 | 'driver' => 'ably', 52 | 'key' => env('ABLY_KEY'), 53 | ], 54 | 55 | 'redis' => [ 56 | 'driver' => 'redis', 57 | 'connection' => 'default', 58 | ], 59 | 60 | 'log' => [ 61 | 'driver' => 'log', 62 | ], 63 | 64 | 'null' => [ 65 | 'driver' => 'null', 66 | ], 67 | 68 | ], 69 | 70 | ]; 71 | -------------------------------------------------------------------------------- /config/cart.php: -------------------------------------------------------------------------------- 1 | [ 5 | 'key' => env('CART_SESSION_KEY', 'cart_session'), 6 | ], 7 | ]; -------------------------------------------------------------------------------- /config/cors.php: -------------------------------------------------------------------------------- 1 | ['api/*', 'sanctum/csrf-cookie'], 19 | 20 | 'allowed_methods' => ['*'], 21 | 22 | 'allowed_origins' => ['*'], 23 | 24 | 'allowed_origins_patterns' => [], 25 | 26 | 'allowed_headers' => ['*'], 27 | 28 | 'exposed_headers' => [], 29 | 30 | 'max_age' => 0, 31 | 32 | 'supports_credentials' => false, 33 | 34 | ]; 35 | -------------------------------------------------------------------------------- /config/hashing.php: -------------------------------------------------------------------------------- 1 | 'bcrypt', 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Bcrypt Options 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may specify the configuration options that should be used when 26 | | passwords are hashed using the Bcrypt algorithm. This will allow you 27 | | to control the amount of time it takes to hash the given password. 28 | | 29 | */ 30 | 31 | 'bcrypt' => [ 32 | 'rounds' => env('BCRYPT_ROUNDS', 10), 33 | ], 34 | 35 | /* 36 | |-------------------------------------------------------------------------- 37 | | Argon Options 38 | |-------------------------------------------------------------------------- 39 | | 40 | | Here you may specify the configuration options that should be used when 41 | | passwords are hashed using the Argon algorithm. These will allow you 42 | | to control the amount of time it takes to hash the given password. 43 | | 44 | */ 45 | 46 | 'argon' => [ 47 | 'memory' => 65536, 48 | 'threads' => 1, 49 | 'time' => 4, 50 | ], 51 | 52 | ]; 53 | -------------------------------------------------------------------------------- /config/money.php: -------------------------------------------------------------------------------- 1 | config('app.locale', 'en_US'), 10 | 'defaultCurrency' => config('app.currency', 'USD'), 11 | 'defaultFormatter' => null, 12 | 'isoCurrenciesPath' => __DIR__.'/../vendor/moneyphp/money/resources/currency.php', 13 | 'currencies' => [ 14 | 'iso' => 'all', 15 | 'bitcoin' => 'all', 16 | 'custom' => [ 17 | // 'MY1' => 2, 18 | // 'MY2' => 3 19 | ], 20 | ], 21 | ]; 22 | -------------------------------------------------------------------------------- /config/sanctum.php: -------------------------------------------------------------------------------- 1 | explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf( 19 | '%s%s', 20 | 'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1', 21 | Sanctum::currentApplicationUrlWithPort() 22 | ))), 23 | 24 | /* 25 | |-------------------------------------------------------------------------- 26 | | Sanctum Guards 27 | |-------------------------------------------------------------------------- 28 | | 29 | | This array contains the authentication guards that will be checked when 30 | | Sanctum is trying to authenticate a request. If none of these guards 31 | | are able to authenticate the request, Sanctum will use the bearer 32 | | token that's present on an incoming request for authentication. 33 | | 34 | */ 35 | 36 | 'guard' => ['web'], 37 | 38 | /* 39 | |-------------------------------------------------------------------------- 40 | | Expiration Minutes 41 | |-------------------------------------------------------------------------- 42 | | 43 | | This value controls the number of minutes until an issued token will be 44 | | considered expired. If this value is null, personal access tokens do 45 | | not expire. This won't tweak the lifetime of first-party sessions. 46 | | 47 | */ 48 | 49 | 'expiration' => null, 50 | 51 | /* 52 | |-------------------------------------------------------------------------- 53 | | Sanctum Middleware 54 | |-------------------------------------------------------------------------- 55 | | 56 | | When authenticating your first-party SPA with Sanctum you may need to 57 | | customize some of the middleware Sanctum uses while processing the 58 | | request. You may change the middleware listed below as required. 59 | | 60 | */ 61 | 62 | 'middleware' => [ 63 | 'verify_csrf_token' => App\Http\Middleware\VerifyCsrfToken::class, 64 | 'encrypt_cookies' => App\Http\Middleware\EncryptCookies::class, 65 | ], 66 | 67 | ]; 68 | -------------------------------------------------------------------------------- /config/services.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'domain' => env('MAILGUN_DOMAIN'), 19 | 'secret' => env('MAILGUN_SECRET'), 20 | 'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'), 21 | 'scheme' => 'https', 22 | ], 23 | 24 | 'postmark' => [ 25 | 'token' => env('POSTMARK_TOKEN'), 26 | ], 27 | 28 | 'ses' => [ 29 | 'key' => env('AWS_ACCESS_KEY_ID'), 30 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 31 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 32 | ], 33 | 34 | 'shop' => [ 35 | 'lowStock' => env('SHOP_LOW_STOCK', '5'), 36 | ], 37 | 38 | ]; 39 | -------------------------------------------------------------------------------- /config/stripe.php: -------------------------------------------------------------------------------- 1 | env('STRIPE_KEY'), 5 | 'secret' => env('STRIPE_SECRET'), 6 | ]; 7 | -------------------------------------------------------------------------------- /config/view.php: -------------------------------------------------------------------------------- 1 | [ 17 | resource_path('views'), 18 | ], 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Compiled View Path 23 | |-------------------------------------------------------------------------- 24 | | 25 | | This option determines where all the compiled Blade templates will be 26 | | stored for your application. Typically, this is within the storage 27 | | directory. However, as usual, you are free to change this value. 28 | | 29 | */ 30 | 31 | 'compiled' => env( 32 | 'VIEW_COMPILED_PATH', 33 | realpath(storage_path('framework/views')) 34 | ), 35 | 36 | ]; 37 | -------------------------------------------------------------------------------- /database/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite* 2 | -------------------------------------------------------------------------------- /database/factories/CartFactory.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class CartFactory extends Factory 11 | { 12 | /** 13 | * Define the model's default state. 14 | * 15 | * @return array 16 | */ 17 | public function definition() 18 | { 19 | return [ 20 | // 21 | ]; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /database/factories/CategoryFactory.php: -------------------------------------------------------------------------------- 1 | 10 | */ 11 | class CategoryFactory extends Factory 12 | { 13 | /** 14 | * Define the model's default state. 15 | * 16 | * @return array 17 | */ 18 | public function definition() 19 | { 20 | $title = $this->faker->sentence(2); 21 | 22 | return [ 23 | 'title' => $title, 24 | 'slug' => Str::slug($title), 25 | 'parent_id' => '', 26 | ]; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /database/factories/OrderFactory.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class OrderFactory extends Factory 11 | { 12 | /** 13 | * Define the model's default state. 14 | * 15 | * @return array 16 | */ 17 | public function definition() 18 | { 19 | return [ 20 | // 21 | ]; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /database/factories/ProductFactory.php: -------------------------------------------------------------------------------- 1 | 10 | */ 11 | class ProductFactory extends Factory 12 | { 13 | /** 14 | * Define the model's default state. 15 | * 16 | * @return array 17 | */ 18 | public function definition(): array 19 | { 20 | $title = $this->faker->sentence(3); 21 | 22 | return [ 23 | 'title' => $title, 24 | 'slug' => Str::slug($title), 25 | 'description' => $this->faker->text(), 26 | 'price' => $this->faker->numberBetween(10000, 50000), 27 | 'live_at' => $this->faker->dateTime, 28 | ]; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /database/factories/ShippingAddressFactory.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class ShippingAddressFactory extends Factory 11 | { 12 | /** 13 | * Define the model's default state. 14 | * 15 | * @return array 16 | */ 17 | public function definition(): array 18 | { 19 | return [ 20 | 'address' => $this->faker->address(), 21 | 'city' => $this->faker->city(), 22 | 'postcode' => $this->faker->postcode(), 23 | ]; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /database/factories/ShippingTypeFactory.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class ShippingTypeFactory extends Factory 11 | { 12 | /** 13 | * Define the model's default state. 14 | * 15 | * @return array 16 | */ 17 | public function definition(): array 18 | { 19 | return [ 20 | 'title' => $this->faker->company(), 21 | 'price' => $this->faker->numberBetween(0, 30000), 22 | ]; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /database/factories/StockFactory.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class StockFactory extends Factory 11 | { 12 | /** 13 | * Define the model's default state. 14 | * 15 | * @return array 16 | */ 17 | public function definition(): array 18 | { 19 | return [ 20 | 'variation_id' => '', 21 | 'amount' => $this->faker->numberBetween(0, 10), 22 | ]; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /database/factories/UserFactory.php: -------------------------------------------------------------------------------- 1 | 10 | */ 11 | class UserFactory extends Factory 12 | { 13 | /** 14 | * Define the model's default state. 15 | * 16 | * @return array 17 | */ 18 | public function definition() 19 | { 20 | return [ 21 | 'name' => fake()->name(), 22 | 'email' => fake()->unique()->safeEmail(), 23 | 'email_verified_at' => now(), 24 | 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password 25 | 'remember_token' => Str::random(10), 26 | ]; 27 | } 28 | 29 | /** 30 | * Indicate that the model's email address should be unverified. 31 | * 32 | * @return static 33 | */ 34 | public function unverified() 35 | { 36 | return $this->state(fn (array $attributes) => [ 37 | 'email_verified_at' => null, 38 | ]); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /database/factories/VariationFactory.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class VariationFactory extends Factory 11 | { 12 | /** 13 | * Define the model's default state. 14 | * 15 | * @return array 16 | */ 17 | public function definition(): array 18 | { 19 | return [ 20 | 'product_id' => '', 21 | 'title' => '', 22 | 'price' => $this->faker->numberBetween(10000, 40000), 23 | 'type' => '', 24 | 'sku' => '', 25 | 'parent_id' => '', 26 | 'order' => 0, 27 | ]; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /database/migrations/2014_10_12_000000_create_users_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->string('name'); 19 | $table->string('email')->unique(); 20 | $table->timestamp('email_verified_at')->nullable(); 21 | $table->string('password'); 22 | $table->rememberToken(); 23 | $table->timestamps(); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | * 30 | * @return void 31 | */ 32 | public function down() 33 | { 34 | Schema::dropIfExists('users'); 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /database/migrations/2014_10_12_100000_create_password_resets_table.php: -------------------------------------------------------------------------------- 1 | string('email')->index(); 18 | $table->string('token'); 19 | $table->timestamp('created_at')->nullable(); 20 | }); 21 | } 22 | 23 | /** 24 | * Reverse the migrations. 25 | * 26 | * @return void 27 | */ 28 | public function down() 29 | { 30 | Schema::dropIfExists('password_resets'); 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /database/migrations/2019_08_19_000000_create_failed_jobs_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->string('uuid')->unique(); 19 | $table->text('connection'); 20 | $table->text('queue'); 21 | $table->longText('payload'); 22 | $table->longText('exception'); 23 | $table->timestamp('failed_at')->useCurrent(); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | * 30 | * @return void 31 | */ 32 | public function down() 33 | { 34 | Schema::dropIfExists('failed_jobs'); 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->morphs('tokenable'); 19 | $table->string('name'); 20 | $table->string('token', 64)->unique(); 21 | $table->text('abilities')->nullable(); 22 | $table->timestamp('last_used_at')->nullable(); 23 | $table->timestamp('expires_at')->nullable(); 24 | $table->timestamps(); 25 | }); 26 | } 27 | 28 | /** 29 | * Reverse the migrations. 30 | * 31 | * @return void 32 | */ 33 | public function down() 34 | { 35 | Schema::dropIfExists('personal_access_tokens'); 36 | } 37 | }; 38 | -------------------------------------------------------------------------------- /database/migrations/2022_11_30_220245_create_categories_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->string('title'); 19 | $table->string('slug')->unique(); 20 | $table->unsignedBigInteger('parent_id')->nullable(); // used for nested categories 21 | $table->timestamps(); 22 | }); 23 | } 24 | 25 | /** 26 | * Reverse the migrations. 27 | * 28 | * @return void 29 | */ 30 | public function down() 31 | { 32 | Schema::dropIfExists('categories'); 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /database/migrations/2022_12_04_184109_create_products_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->string('title'); 19 | $table->string('slug')->unique(); 20 | $table->string('description')->nullable(); 21 | $table->integer('price')->unsigned(); // never negative 22 | $table->dateTime('live_at')->nullable(); 23 | $table->timestamps(); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | * 30 | * @return void 31 | */ 32 | public function down() 33 | { 34 | Schema::dropIfExists('products'); 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /database/migrations/2022_12_04_203415_create_variations_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->foreignId('product_id')->constrained(); 19 | $table->string('title'); 20 | $table->integer('price')->unsigned()->default(0); 21 | $table->string('type'); // color, size, etc. 22 | $table->string('sku')->nullable(); 23 | $table->unsignedBigInteger('parent_id')->nullable(); // under `black` you might have variations of 10,11,12 24 | $table->integer('order')->nullable(); 25 | $table->timestamps(); 26 | }); 27 | } 28 | 29 | /** 30 | * Reverse the migrations. 31 | * 32 | * @return void 33 | */ 34 | public function down() 35 | { 36 | Schema::dropIfExists('variations'); 37 | } 38 | }; 39 | -------------------------------------------------------------------------------- /database/migrations/2022_12_07_122402_create_stocks_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->foreignId('variation_id')->constrained(); 19 | $table->integer('amount'); 20 | $table->timestamps(); 21 | }); 22 | } 23 | 24 | /** 25 | * Reverse the migrations. 26 | * 27 | * @return void 28 | */ 29 | public function down() 30 | { 31 | Schema::dropIfExists('stocks'); 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /database/migrations/2022_12_09_115140_create_media_table.php: -------------------------------------------------------------------------------- 1 | bigIncrements('id'); 13 | 14 | $table->morphs('model'); 15 | $table->uuid('uuid')->nullable()->unique(); 16 | $table->string('collection_name'); 17 | $table->string('name'); 18 | $table->string('file_name'); 19 | $table->string('mime_type')->nullable(); 20 | $table->string('disk'); 21 | $table->string('conversions_disk')->nullable(); 22 | $table->unsignedBigInteger('size'); 23 | $table->json('manipulations'); 24 | $table->json('custom_properties'); 25 | $table->json('generated_conversions'); 26 | $table->json('responsive_images'); 27 | $table->unsignedInteger('order_column')->nullable()->index(); 28 | 29 | $table->nullableTimestamps(); 30 | }); 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /database/migrations/2022_12_10_221151_create_carts_table.php: -------------------------------------------------------------------------------- 1 | id(); 13 | $table->uuid('uuid'); // unique cart identifier that is stored inside the session 14 | $table->foreignId('user_id')->nullable()->constrained(); // Anonymous users can add items to cart 15 | $table->timestamps(); 16 | }); 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /database/migrations/2022_12_10_221648_creatr_cart_variation_table.php: -------------------------------------------------------------------------------- 1 | id(); 13 | $table->foreignId('cart_id')->constrained(); 14 | $table->foreignId('variation_id')->constrained(); // item added to cart 15 | $table->integer('quantity'); 16 | $table->timestamps(); 17 | }); 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /database/migrations/2022_12_19_073915_create_category_product_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->foreignId('category_id')->constrained(); 19 | $table->foreignId('product_id')->constrained(); 20 | $table->timestamps(); 21 | }); 22 | } 23 | 24 | /** 25 | * Reverse the migrations. 26 | * 27 | * @return void 28 | */ 29 | public function down() 30 | { 31 | Schema::dropIfExists('category_product'); 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /database/migrations/2023_01_09_082248_create_shipping_types_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->string('title'); 19 | $table->integer('price'); 20 | $table->timestamps(); 21 | }); 22 | } 23 | 24 | /** 25 | * Reverse the migrations. 26 | * 27 | * @return void 28 | */ 29 | public function down() 30 | { 31 | Schema::dropIfExists('shipping_types'); 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /database/migrations/2023_01_10_095329_create_shipping_addresses_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->foreignId('user_id')->nullable(); // for non-authenticated users, we still need to create a shipping address 19 | $table->string('address'); 20 | $table->string('city'); 21 | $table->string('postcode'); 22 | $table->timestamps(); 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | * 29 | * @return void 30 | */ 31 | public function down() 32 | { 33 | Schema::dropIfExists('shipping_addresses'); 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /database/migrations/2023_01_13_065822_create_orders_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->uuid('uuid'); // a unique order number 19 | $table->string('email'); // user who is checking out 20 | $table->foreignId('user_id')->nullable()->constrained(); // a non-logged in user can create orders 21 | $table->foreignId('shipping_address_id')->constrained(); 22 | $table->foreignId('shipping_type_id')->constrained(); 23 | $table->integer('subtotal'); 24 | $table->timestamp('placed_at'); 25 | $table->timestamp('packaged_at')->nullable(); 26 | $table->timestamp('shipped_at')->nullable(); 27 | $table->timestamps(); 28 | }); 29 | } 30 | 31 | /** 32 | * Reverse the migrations. 33 | * 34 | * @return void 35 | */ 36 | public function down() 37 | { 38 | Schema::dropIfExists('orders'); 39 | } 40 | }; 41 | -------------------------------------------------------------------------------- /database/migrations/2023_01_13_125310_create_order_variation_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->foreignId('order_id')->constrained(); 19 | $table->foreignId('variation_id')->constrained(); // item added to cart 20 | $table->integer('quantity'); 21 | $table->timestamps(); 22 | }); 23 | } 24 | 25 | /** 26 | * Reverse the migrations. 27 | * 28 | * @return void 29 | */ 30 | public function down() 31 | { 32 | Schema::dropIfExists('order_variation'); 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /database/migrations/2023_01_17_204558_add_payment_intent_id_on_carts_table.php: -------------------------------------------------------------------------------- 1 | string('payment_intent_id')->nullable(); 18 | }); 19 | } 20 | 21 | /** 22 | * Reverse the migrations. 23 | * 24 | * @return void 25 | */ 26 | public function down() 27 | { 28 | // 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /database/seeders/CartSeeder.php: -------------------------------------------------------------------------------- 1 | create([ 20 | 'title' => 'Brands', 21 | 'slug' => Str::slug('Brands'), 22 | 'parent_id' => null, 23 | ])->each(function (Category $category) { 24 | $this->callWith(ProductSeeder::class, ['categoryId' => $category->id]); 25 | })->first(); 26 | 27 | $nike = Category::factory(1)->create([ 28 | 'title' => 'Nike', 29 | 'slug' => Str::slug('Nike'), 30 | 'parent_id' => $brand->id, 31 | ])->each(function (Category $category) { 32 | $this->callWith(ProductSeeder::class, ['categoryId' => $category->id]); 33 | })->first(); 34 | 35 | Category::factory(1)->create([ 36 | 'title' => 'Shoes', 37 | 'slug' => Str::slug('Shoes'), 38 | 'parent_id' => $nike->id, 39 | ])->each(function (Category $category) { 40 | $this->callWith(ProductSeeder::class, ['categoryId' => $category->id]); 41 | }); 42 | 43 | $seasons = Category::factory(1)->create([ 44 | 'title' => 'Seasons', 45 | 'slug' => Str::slug('Seasons'), 46 | 'parent_id' => null, 47 | ])->each(function (Category $category) { 48 | $this->callWith(ProductSeeder::class, ['categoryId' => $category->id]); 49 | })->first(); 50 | 51 | Category::factory(1)->create([ 52 | 'title' => 'Summer', 53 | 'slug' => Str::slug('Summer'), 54 | 'parent_id' => $seasons->id, 55 | ])->each(function (Category $category) { 56 | $this->callWith(ProductSeeder::class, ['categoryId' => $category->id]); 57 | }); 58 | 59 | Category::factory(1)->create([ 60 | 'title' => 'Winter', 61 | 'slug' => Str::slug('Winter'), 62 | 'parent_id' => $seasons->id, 63 | ])->each(function (Category $category) { 64 | $this->callWith(ProductSeeder::class, ['categoryId' => $category->id]); 65 | }); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /database/seeders/DatabaseSeeder.php: -------------------------------------------------------------------------------- 1 | call(UserSeeder::class); 20 | $this->call(CategorySeeder::class); 21 | $this->call(VariationSeeder::class); 22 | $this->call(ShippingTypeSeeder::class); 23 | $this->callWith(ShippingAddressSeeder::class, ['user_id' => User::first()->id]); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /database/seeders/OrderSeeder.php: -------------------------------------------------------------------------------- 1 | find($categoryId); 20 | 21 | $files = [ 22 | 'black' => './nike-air1-black.png', 23 | 'white' => './nike-air1-white.png' 24 | ]; 25 | 26 | Product::factory(2)->create()->each(function (Product $product) use ($files, $category) { 27 | $product->addMedia($files[array_rand($files)]) 28 | ->preservingOriginal() 29 | ->toMediaCollection(); 30 | 31 | $category->products()->attach($product); 32 | }); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /database/seeders/ShippingAddressSeeder.php: -------------------------------------------------------------------------------- 1 | create([ 19 | 'user_id' => $user_id, 20 | ]); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /database/seeders/ShippingTypeSeeder.php: -------------------------------------------------------------------------------- 1 | create(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /database/seeders/StockSeeder.php: -------------------------------------------------------------------------------- 1 | create([ 20 | 'variation_id' => $variation, 21 | ]); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /database/seeders/UserSeeder.php: -------------------------------------------------------------------------------- 1 | create([ 19 | 'email' => 'bhaidar@gmail.com', 20 | 'password' => bcrypt('secret'), 21 | ]); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "paths": { 5 | "@/*": ["resources/js/*"] 6 | } 7 | }, 8 | "exclude": ["node_modules", "public"] 9 | } 10 | -------------------------------------------------------------------------------- /lang/en/auth.php: -------------------------------------------------------------------------------- 1 | 'These credentials do not match our records.', 17 | 'password' => 'The provided password is incorrect.', 18 | 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', 19 | 20 | ]; 21 | -------------------------------------------------------------------------------- /lang/en/pagination.php: -------------------------------------------------------------------------------- 1 | '« Previous', 17 | 'next' => 'Next »', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /lang/en/passwords.php: -------------------------------------------------------------------------------- 1 | 'Your password has been reset!', 17 | 'sent' => 'We have emailed your password reset link!', 18 | 'throttled' => 'Please wait before retrying.', 19 | 'token' => 'This password reset token is invalid.', 20 | 'user' => "We can't find a user with that email address.", 21 | 22 | ]; 23 | -------------------------------------------------------------------------------- /nike-air1-black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bhaidar/laravel-ecommerce-inertiajs/411e63d253df8e476935f7f88179972234d55999/nike-air1-black.png -------------------------------------------------------------------------------- /nike-air1-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bhaidar/laravel-ecommerce-inertiajs/411e63d253df8e476935f7f88179972234d55999/nike-air1-white.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "dev": "vite", 5 | "build": "vite build" 6 | }, 7 | "devDependencies": { 8 | "@inertiajs/inertia": "^0.11.0", 9 | "@inertiajs/inertia-vue3": "^0.6.0", 10 | "@inertiajs/progress": "^0.2.7", 11 | "@tailwindcss/forms": "^0.5.3", 12 | "@vitejs/plugin-vue": "^3.0.0", 13 | "autoprefixer": "^10.4.12", 14 | "axios": "^1.1.2", 15 | "laravel-vite-plugin": "^0.7.0", 16 | "lodash": "^4.17.19", 17 | "postcss": "^8.4.18", 18 | "tailwindcss": "^3.2.1", 19 | "vite": "^3.0.0", 20 | "vue": "^3.2.41" 21 | }, 22 | "dependencies": { 23 | "@heroicons/vue": "^2.0.13" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | ./tests/Unit 10 | 11 | 12 | ./tests/Feature 13 | 14 | 15 | 16 | 17 | ./app 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | }; 7 | -------------------------------------------------------------------------------- /public/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bhaidar/laravel-ecommerce-inertiajs/411e63d253df8e476935f7f88179972234d55999/public/.DS_Store -------------------------------------------------------------------------------- /public/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | 3 | Options -MultiViews -Indexes 4 | 5 | 6 | RewriteEngine On 7 | 8 | # Handle Authorization Header 9 | RewriteCond %{HTTP:Authorization} . 10 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 11 | 12 | # Redirect Trailing Slashes If Not A Folder... 13 | RewriteCond %{REQUEST_FILENAME} !-d 14 | RewriteCond %{REQUEST_URI} (.+)/$ 15 | RewriteRule ^ %1 [L,R=301] 16 | 17 | # Send Requests To Front Controller... 18 | RewriteCond %{REQUEST_FILENAME} !-d 19 | RewriteCond %{REQUEST_FILENAME} !-f 20 | RewriteRule ^ index.php [L] 21 | 22 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bhaidar/laravel-ecommerce-inertiajs/411e63d253df8e476935f7f88179972234d55999/public/favicon.ico -------------------------------------------------------------------------------- /public/images/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bhaidar/laravel-ecommerce-inertiajs/411e63d253df8e476935f7f88179972234d55999/public/images/.DS_Store -------------------------------------------------------------------------------- /public/images/no_image_available.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bhaidar/laravel-ecommerce-inertiajs/411e63d253df8e476935f7f88179972234d55999/public/images/no_image_available.png -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | make(Kernel::class); 50 | 51 | $response = $kernel->handle( 52 | $request = Request::capture() 53 | )->send(); 54 | 55 | $kernel->terminate($request, $response); 56 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /resources/css/app.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | -------------------------------------------------------------------------------- /resources/js/Components/Cart/Cart.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | -------------------------------------------------------------------------------- /resources/js/Components/Cart/CartItem.vue: -------------------------------------------------------------------------------- 1 | 33 | 34 | -------------------------------------------------------------------------------- /resources/js/Components/Checkbox.vue: -------------------------------------------------------------------------------- 1 | 26 | 27 | 35 | -------------------------------------------------------------------------------- /resources/js/Components/DangerButton.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 18 | -------------------------------------------------------------------------------- /resources/js/Components/Dropdown.vue: -------------------------------------------------------------------------------- 1 | 43 | 44 | 75 | -------------------------------------------------------------------------------- /resources/js/Components/DropdownLink.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 12 | -------------------------------------------------------------------------------- /resources/js/Components/GlobalSearch.vue: -------------------------------------------------------------------------------- 1 | 19 | 20 | -------------------------------------------------------------------------------- /resources/js/Components/Icon.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | -------------------------------------------------------------------------------- /resources/js/Components/InputError.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 12 | -------------------------------------------------------------------------------- /resources/js/Components/InputLabel.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 11 | -------------------------------------------------------------------------------- /resources/js/Components/LinkButton.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | 17 | -------------------------------------------------------------------------------- /resources/js/Components/NavLink.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 19 | -------------------------------------------------------------------------------- /resources/js/Components/PrimaryButton.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 18 | -------------------------------------------------------------------------------- /resources/js/Components/Products/Category.vue: -------------------------------------------------------------------------------- 1 | 14 | 15 | -------------------------------------------------------------------------------- /resources/js/Components/Products/ProductDropdown.vue: -------------------------------------------------------------------------------- 1 | 34 | 35 | 62 | -------------------------------------------------------------------------------- /resources/js/Components/Products/ProductGallery.vue: -------------------------------------------------------------------------------- 1 | 17 | 18 | -------------------------------------------------------------------------------- /resources/js/Components/Products/ProductSelector.vue: -------------------------------------------------------------------------------- 1 | 40 | 41 | -------------------------------------------------------------------------------- /resources/js/Components/ResponsiveNavLink.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 19 | -------------------------------------------------------------------------------- /resources/js/Components/SecondaryButton.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 18 | -------------------------------------------------------------------------------- /resources/js/Components/Select.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | -------------------------------------------------------------------------------- /resources/js/Components/TextInput.vue: -------------------------------------------------------------------------------- 1 | 18 | 19 | 27 | -------------------------------------------------------------------------------- /resources/js/Layouts/AppLayout.vue: -------------------------------------------------------------------------------- 1 | 5 | 6 | 29 | -------------------------------------------------------------------------------- /resources/js/Layouts/GuestLayout.vue: -------------------------------------------------------------------------------- 1 | 5 | 6 | 21 | -------------------------------------------------------------------------------- /resources/js/Pages/Auth/ConfirmPassword.vue: -------------------------------------------------------------------------------- 1 | 19 | 20 | 51 | -------------------------------------------------------------------------------- /resources/js/Pages/Auth/ForgotPassword.vue: -------------------------------------------------------------------------------- 1 | 21 | 22 | 60 | -------------------------------------------------------------------------------- /resources/js/Pages/Auth/VerifyEmail.vue: -------------------------------------------------------------------------------- 1 | 19 | 20 | 50 | -------------------------------------------------------------------------------- /resources/js/Pages/Cart/Index.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 28 | -------------------------------------------------------------------------------- /resources/js/Pages/Categories/Show.vue: -------------------------------------------------------------------------------- 1 | 29 | 30 | -------------------------------------------------------------------------------- /resources/js/Pages/Dashboard.vue: -------------------------------------------------------------------------------- 1 | 5 | 6 | 27 | -------------------------------------------------------------------------------- /resources/js/Pages/Orders/Confirmation.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 34 | -------------------------------------------------------------------------------- /resources/js/Pages/Products/SearchResults.vue: -------------------------------------------------------------------------------- 1 | 17 | 18 | -------------------------------------------------------------------------------- /resources/js/Pages/Products/Show.vue: -------------------------------------------------------------------------------- 1 | 15 | 16 | -------------------------------------------------------------------------------- /resources/js/Pages/Profile/Edit.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 43 | -------------------------------------------------------------------------------- /resources/js/Pages/Welcome.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 25 | -------------------------------------------------------------------------------- /resources/js/app.js: -------------------------------------------------------------------------------- 1 | import './bootstrap'; 2 | import '../css/app.css'; 3 | 4 | import { createApp, h } from 'vue'; 5 | import { createInertiaApp } from '@inertiajs/inertia-vue3'; 6 | import { InertiaProgress } from '@inertiajs/progress'; 7 | import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers'; 8 | import { ZiggyVue } from '../../vendor/tightenco/ziggy/dist/vue.m'; 9 | 10 | const appName = window.document.getElementsByTagName('title')[0]?.innerText || 'Laravel'; 11 | 12 | createInertiaApp({ 13 | title: (title) => `${title} - ${appName}`, 14 | resolve: (name) => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')), 15 | setup({ el, app, props, plugin }) { 16 | return createApp({ render: () => h(app, props) }) 17 | .use(plugin) 18 | .use(ZiggyVue, Ziggy) 19 | .mount(el); 20 | }, 21 | }); 22 | 23 | InertiaProgress.init({ color: '#4B5563' }); 24 | -------------------------------------------------------------------------------- /resources/js/bootstrap.js: -------------------------------------------------------------------------------- 1 | import _ from 'lodash'; 2 | window._ = _; 3 | 4 | /** 5 | * We'll load the axios HTTP library which allows us to easily issue requests 6 | * to our Laravel back-end. This library automatically handles sending the 7 | * CSRF token as a header based on the value of the "XSRF" token cookie. 8 | */ 9 | 10 | import axios from 'axios'; 11 | window.axios = axios; 12 | 13 | window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; 14 | 15 | /** 16 | * Echo exposes an expressive API for subscribing to channels and listening 17 | * for events that are broadcast by Laravel. Echo and event broadcasting 18 | * allows your team to easily build robust real-time web applications. 19 | */ 20 | 21 | // import Echo from 'laravel-echo'; 22 | 23 | // import Pusher from 'pusher-js'; 24 | // window.Pusher = Pusher; 25 | 26 | // window.Echo = new Echo({ 27 | // broadcaster: 'pusher', 28 | // key: import.meta.env.VITE_PUSHER_APP_KEY, 29 | // wsHost: import.meta.env.VITE_PUSHER_HOST ? import.meta.env.VITE_PUSHER_HOST : `ws-${import.meta.env.VITE_PUSHER_APP_CLUSTER}.pusher.com`, 30 | // wsPort: import.meta.env.VITE_PUSHER_PORT ?? 80, 31 | // wssPort: import.meta.env.VITE_PUSHER_PORT ?? 443, 32 | // forceTLS: (import.meta.env.VITE_PUSHER_SCHEME ?? 'https') === 'https', 33 | // enabledTransports: ['ws', 'wss'], 34 | // }); 35 | -------------------------------------------------------------------------------- /resources/js/helper.js: -------------------------------------------------------------------------------- 1 | const loadScript = (url, callback) => { 2 | let script = document.createElement('script'); 3 | script.src = url; 4 | script.async = true; 5 | script.onload = function() { 6 | console.log(`Script ${url} loaded`); 7 | callback(); 8 | } 9 | script.onerror = function() { 10 | console.log(`Failed to load script ${url}`); 11 | } 12 | document.head.appendChild(script); 13 | }; 14 | 15 | export default loadScript; -------------------------------------------------------------------------------- /resources/views/app.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | {{ config('app.name', 'Laravel') }} 8 | 9 | 10 | 11 | 12 | 13 | @routes 14 | @vite(['resources/js/app.js', "resources/js/Pages/{$page['component']}.vue"]) 15 | @inertiaHead 16 | 17 | 18 | @inertia 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /resources/views/emails/order/created.blade.php: -------------------------------------------------------------------------------- 1 | 2 | # Your order (#{{ $order->id }}) has been placed 3 | 4 | The body of your message. 5 | 6 | 7 | Button Text 8 | 9 | 10 | Thanks,
11 | {{ config('app.name') }} 12 |
13 | -------------------------------------------------------------------------------- /resources/views/emails/order/updated.blade.php: -------------------------------------------------------------------------------- 1 | 2 | # The status of your order has changed 3 | 4 | The body of your message. 5 | 6 | 7 | Button Text 8 | 9 | 10 | Thanks,
11 | {{ config('app.name') }} 12 |
13 | -------------------------------------------------------------------------------- /routes/api.php: -------------------------------------------------------------------------------- 1 | get('/user', function (Request $request) { 18 | return $request->user(); 19 | }); 20 | -------------------------------------------------------------------------------- /routes/channels.php: -------------------------------------------------------------------------------- 1 | id === (int) $id; 18 | }); 19 | -------------------------------------------------------------------------------- /routes/console.php: -------------------------------------------------------------------------------- 1 | comment(Inspiring::quote()); 19 | })->purpose('Display an inspiring quote'); 20 | -------------------------------------------------------------------------------- /storage/app/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !public/ 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /storage/app/public/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/debugbar/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/.gitignore: -------------------------------------------------------------------------------- 1 | compiled.php 2 | config.php 3 | down 4 | events.scanned.php 5 | maintenance.php 6 | routes.php 7 | routes.scanned.php 8 | schedule-* 9 | services.json 10 | -------------------------------------------------------------------------------- /storage/framework/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !data/ 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /storage/framework/cache/data/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/sessions/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/testing/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/views/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/logs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | const defaultTheme = require('tailwindcss/defaultTheme'); 2 | 3 | /** @type {import('tailwindcss').Config} */ 4 | module.exports = { 5 | content: [ 6 | './vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php', 7 | './storage/framework/views/*.php', 8 | './resources/views/**/*.blade.php', 9 | './resources/js/**/*.vue', 10 | ], 11 | 12 | theme: { 13 | extend: { 14 | fontFamily: { 15 | sans: ['Nunito', ...defaultTheme.fontFamily.sans], 16 | }, 17 | }, 18 | }, 19 | 20 | plugins: [require('@tailwindcss/forms')], 21 | }; 22 | -------------------------------------------------------------------------------- /tests/CreatesApplication.php: -------------------------------------------------------------------------------- 1 | make(Kernel::class)->bootstrap(); 19 | 20 | return $app; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/Feature/Auth/AuthenticationTest.php: -------------------------------------------------------------------------------- 1 | get('/login'); 17 | 18 | $response->assertStatus(200); 19 | } 20 | 21 | public function test_users_can_authenticate_using_the_login_screen() 22 | { 23 | $user = User::factory()->create(); 24 | 25 | $response = $this->post('/login', [ 26 | 'email' => $user->email, 27 | 'password' => 'password', 28 | ]); 29 | 30 | $this->assertAuthenticated(); 31 | $response->assertRedirect(RouteServiceProvider::HOME); 32 | } 33 | 34 | public function test_users_can_not_authenticate_with_invalid_password() 35 | { 36 | $user = User::factory()->create(); 37 | 38 | $this->post('/login', [ 39 | 'email' => $user->email, 40 | 'password' => 'wrong-password', 41 | ]); 42 | 43 | $this->assertGuest(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/Feature/Auth/EmailVerificationTest.php: -------------------------------------------------------------------------------- 1 | create([ 20 | 'email_verified_at' => null, 21 | ]); 22 | 23 | $response = $this->actingAs($user)->get('/verify-email'); 24 | 25 | $response->assertStatus(200); 26 | } 27 | 28 | public function test_email_can_be_verified() 29 | { 30 | $user = User::factory()->create([ 31 | 'email_verified_at' => null, 32 | ]); 33 | 34 | Event::fake(); 35 | 36 | $verificationUrl = URL::temporarySignedRoute( 37 | 'verification.verify', 38 | now()->addMinutes(60), 39 | ['id' => $user->id, 'hash' => sha1($user->email)] 40 | ); 41 | 42 | $response = $this->actingAs($user)->get($verificationUrl); 43 | 44 | Event::assertDispatched(Verified::class); 45 | $this->assertTrue($user->fresh()->hasVerifiedEmail()); 46 | $response->assertRedirect(RouteServiceProvider::HOME.'?verified=1'); 47 | } 48 | 49 | public function test_email_is_not_verified_with_invalid_hash() 50 | { 51 | $user = User::factory()->create([ 52 | 'email_verified_at' => null, 53 | ]); 54 | 55 | $verificationUrl = URL::temporarySignedRoute( 56 | 'verification.verify', 57 | now()->addMinutes(60), 58 | ['id' => $user->id, 'hash' => sha1('wrong-email')] 59 | ); 60 | 61 | $this->actingAs($user)->get($verificationUrl); 62 | 63 | $this->assertFalse($user->fresh()->hasVerifiedEmail()); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /tests/Feature/Auth/PasswordConfirmationTest.php: -------------------------------------------------------------------------------- 1 | create(); 16 | 17 | $response = $this->actingAs($user)->get('/confirm-password'); 18 | 19 | $response->assertStatus(200); 20 | } 21 | 22 | public function test_password_can_be_confirmed() 23 | { 24 | $user = User::factory()->create(); 25 | 26 | $response = $this->actingAs($user)->post('/confirm-password', [ 27 | 'password' => 'password', 28 | ]); 29 | 30 | $response->assertRedirect(); 31 | $response->assertSessionHasNoErrors(); 32 | } 33 | 34 | public function test_password_is_not_confirmed_with_invalid_password() 35 | { 36 | $user = User::factory()->create(); 37 | 38 | $response = $this->actingAs($user)->post('/confirm-password', [ 39 | 'password' => 'wrong-password', 40 | ]); 41 | 42 | $response->assertSessionHasErrors(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/Feature/Auth/PasswordResetTest.php: -------------------------------------------------------------------------------- 1 | get('/forgot-password'); 18 | 19 | $response->assertStatus(200); 20 | } 21 | 22 | public function test_reset_password_link_can_be_requested() 23 | { 24 | Notification::fake(); 25 | 26 | $user = User::factory()->create(); 27 | 28 | $this->post('/forgot-password', ['email' => $user->email]); 29 | 30 | Notification::assertSentTo($user, ResetPassword::class); 31 | } 32 | 33 | public function test_reset_password_screen_can_be_rendered() 34 | { 35 | Notification::fake(); 36 | 37 | $user = User::factory()->create(); 38 | 39 | $this->post('/forgot-password', ['email' => $user->email]); 40 | 41 | Notification::assertSentTo($user, ResetPassword::class, function ($notification) { 42 | $response = $this->get('/reset-password/'.$notification->token); 43 | 44 | $response->assertStatus(200); 45 | 46 | return true; 47 | }); 48 | } 49 | 50 | public function test_password_can_be_reset_with_valid_token() 51 | { 52 | Notification::fake(); 53 | 54 | $user = User::factory()->create(); 55 | 56 | $this->post('/forgot-password', ['email' => $user->email]); 57 | 58 | Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) { 59 | $response = $this->post('/reset-password', [ 60 | 'token' => $notification->token, 61 | 'email' => $user->email, 62 | 'password' => 'password', 63 | 'password_confirmation' => 'password', 64 | ]); 65 | 66 | $response->assertSessionHasNoErrors(); 67 | 68 | return true; 69 | }); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /tests/Feature/Auth/PasswordUpdateTest.php: -------------------------------------------------------------------------------- 1 | create(); 17 | 18 | $response = $this 19 | ->actingAs($user) 20 | ->from('/profile') 21 | ->put('/password', [ 22 | 'current_password' => 'password', 23 | 'password' => 'new-password', 24 | 'password_confirmation' => 'new-password', 25 | ]); 26 | 27 | $response 28 | ->assertSessionHasNoErrors() 29 | ->assertRedirect('/profile'); 30 | 31 | $this->assertTrue(Hash::check('new-password', $user->refresh()->password)); 32 | } 33 | 34 | public function test_correct_password_must_be_provided_to_update_password() 35 | { 36 | $user = User::factory()->create(); 37 | 38 | $response = $this 39 | ->actingAs($user) 40 | ->from('/profile') 41 | ->put('/password', [ 42 | 'current_password' => 'wrong-password', 43 | 'password' => 'new-password', 44 | 'password_confirmation' => 'new-password', 45 | ]); 46 | 47 | $response 48 | ->assertSessionHasErrors('current_password') 49 | ->assertRedirect('/profile'); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tests/Feature/Auth/RegistrationTest.php: -------------------------------------------------------------------------------- 1 | get('/register'); 16 | 17 | $response->assertStatus(200); 18 | } 19 | 20 | public function test_new_users_can_register() 21 | { 22 | $response = $this->post('/register', [ 23 | 'name' => 'Test User', 24 | 'email' => 'test@example.com', 25 | 'password' => 'password', 26 | 'password_confirmation' => 'password', 27 | ]); 28 | 29 | $this->assertAuthenticated(); 30 | $response->assertRedirect(RouteServiceProvider::HOME); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/Feature/ExampleTest.php: -------------------------------------------------------------------------------- 1 | get('/'); 18 | 19 | $response->assertStatus(200); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | assertTrue(true); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /vite.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite'; 2 | import laravel from 'laravel-vite-plugin'; 3 | import vue from '@vitejs/plugin-vue'; 4 | 5 | export default defineConfig({ 6 | plugins: [ 7 | laravel({ 8 | input: 'resources/js/app.js', 9 | refresh: true, 10 | }), 11 | vue({ 12 | template: { 13 | transformAssetUrls: { 14 | base: null, 15 | includeAbsolute: false, 16 | }, 17 | }, 18 | }), 19 | ], 20 | }); 21 | --------------------------------------------------------------------------------