### Run Interactive Setup Script Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/installation.md Executes an interactive script to guide the user through the initial setup process of the starter kit. This simplifies configuration by prompting for necessary information. ```bash php bin/setup.php ``` -------------------------------- ### Create Project with Composer Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/installation.md Installs the SuperDuper Filament Starter Kit by creating a new project using Composer. This is the primary method for getting started with the framework. ```bash composer create-project riodwanto/superduper-filament-starter-kit ``` -------------------------------- ### Start Development Server Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/installation.md Starts the local development server provided by Laravel. This allows you to preview your application in a web browser at the specified address. ```bash php artisan serve ``` -------------------------------- ### Environment and Database Setup (Bash) Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/development.md Configures the environment by copying the example .env file, generating an application key, and migrating the database with seeding. This ensures the application has the necessary configuration and data to run. ```bash cp .env.example .env php artisan key:generate php artisan migrate --seed php artisan shield:generate --all php artisan db:seed --class=PermissionsSeeder ``` -------------------------------- ### Copy Environment File Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/installation.md Copies the example environment file to a new file named .env, which will be used to store application-specific configuration settings. ```bash cp .env.example .env ``` -------------------------------- ### Install Frontend Dependencies Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/installation.md Installs all the necessary frontend packages and libraries defined in the project's package.json file using NPM. This is required before building frontend assets. ```bash npm install ``` -------------------------------- ### Build Assets and Start Development Server (Bash) Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/development.md Commands to build front-end assets for development or production and to start the local PHP development server. Useful for testing changes in real-time. ```bash npm run dev # or for production # npm run build php artisan serve ``` -------------------------------- ### Project Setup Commands (Bash) Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/README.md Commands to set up a new Superduper Filament Starter Kit project, including installing dependencies, running migrations, seeding the database, and generating permissions. ```bash composer create-project riodwanto/superduper-filament-starter-kit cd superduper-filament-starter-kit composer install && npm install php artisan superduper:setup php artisan superduper:setup --default cp .env.example .env php artisan migrate php artisan db:seed php artisan migrate:fresh --seed php artisan shield:generate --all php artisan db:seed --class=PermissionsSeeder php artisan key:generate php artisan storage:link npm install npm run dev OR npm run build php artisan serve ``` -------------------------------- ### Clone and Install Dependencies (Bash) Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/development.md Clones the repository and installs both PHP and NPM dependencies. This is the initial step for setting up the development environment. ```bash git clone https://github.com/riodwanto/superduper-filament-starter-kit.git cd superduper-filament-starter-kit composer install npm install ``` -------------------------------- ### Automated Project Setup with SuperDuper Artisan Command Source: https://context7.com/riodwanto/superduper-filament-starter-kit/llms.txt The `superduper:setup` Artisan command automates the initial setup of a Laravel project. It handles environment configuration, database setup, migrations, seeding, and permission generation. The command supports interactive prompts for configuration or uses default values for quick installations, and offers options to skip specific steps or perform a fresh database installation. ```bash php artisan superduper:setup php artisan superduper:setup --default php artisan superduper:setup --fresh php artisan superduper:setup --skip-migrations --skip-seed ``` -------------------------------- ### Production Deployment Steps (Bash) Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/development.md Commands for deploying the application to a production environment. Includes installing dependencies without dev packages, optimizing configuration and routes, and building production assets. ```bash # Install dependencies with --no-dev composer install --optimize-autoloader --no-dev # Optimize the framework php artisan config:cache php artisan route:cache php artisan view:cache # Build production assets npm run build ``` -------------------------------- ### Generate API Documentation (Bash) Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/development.md Installs a package for generating API documentation and then runs the command to generate the documentation. This helps in documenting API endpoints for consumers. ```bash # Install API documentation generator composer require --dev mpociot/laravel-apidoc-generator # Generate documentation php artisan apidoc:generate ``` -------------------------------- ### Development Server Start (Bash) Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/README.md Commands to start the local development server using Artisan and npm. ```bash php artisan serve npm run dev ``` -------------------------------- ### Install and Set Up Laravel Telescope Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/performance.md Commands to install and set up Laravel Telescope, a powerful debugging and monitoring tool for Laravel applications. It helps in inspecting requests, exceptions, database queries, and more. Requires Composer and Artisan CLI access. ```bash composer require laravel/telescope php artisan telescope:install php artisan migrate ``` -------------------------------- ### Run SuperDuper Setup Command Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/commands.md Executes the interactive setup for the SuperDuper Filament Starter Kit. It checks environment, configures .env and database settings, generates keys, creates storage links, runs migrations and seeds, clears cache, and generates Shield permissions. Prerequisites include installed Composer and Node dependencies. ```bash php artisan superduper:setup php artisan superduper:setup --default php artisan superduper:setup --env-backup php artisan superduper:setup --fresh php artisan superduper:setup --skip-migrations --skip-seed ``` -------------------------------- ### Configure Database Settings Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/installation.md Specifies the database connection details within the .env file. This includes the database driver, host, port, name, username, and password. ```env DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=your_database DB_USERNAME=your_username DB_PASSWORD=your_password ``` -------------------------------- ### Install and Run Laravel Dusk Browser Tests (Bash) Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/development.md Installs Laravel Dusk for browser testing and then executes the Dusk test suite. This is used for end-to-end testing of the application's user interface. ```bash # Install Dusk composer require --dev laravel/dusk php artisan dusk:install # Run Dusk tests php artisan dusk ``` -------------------------------- ### Run Database Migrations and Seeders Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/installation.md Applies all pending database migrations and populates the database with initial seed data. This ensures the database schema is set up correctly and contains default information. ```bash php artisan migrate --seed ``` -------------------------------- ### Create Storage Link Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/installation.md Creates a symbolic link from the public directory to the storage directory, allowing publicly accessible files (like uploaded images) to be served correctly. ```bash php artisan storage:link ``` -------------------------------- ### Database Migration and Seeding (Bash) Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/README.md Commands to run database migrations and seed the database, including a combined command for a fresh setup. ```bash php artisan migrate php artisan db:seed php artisan migrate:fresh --seed ``` -------------------------------- ### Troubleshoot APP_KEY Missing Error (Artisan) Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/commands.md Resolves the 'Unable to set application key' error by ensuring the `.env.example` file contains an `APP_KEY` and then re-running the setup command. This process is crucial for application initialization. ```bash # Ensure .env.example has APP_KEY= line # Then re-run setup php artisan superduper:setup ``` -------------------------------- ### Build Frontend Assets Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/installation.md Compiles and optimizes frontend assets (CSS, JavaScript) for development or production. 'npm run dev' is for development, while 'npm run build' is for production environments. ```bash npm run dev # or for production npm run build ``` -------------------------------- ### Superduper Artisan Commands (Bash) Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/README.md Custom Artisan commands provided by the Superduper Filament Starter Kit for specific setup and permission tasks. ```bash php artisan superduper:setup php artisan superduper:permissions ``` -------------------------------- ### Generate Application Key Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/installation.md Generates a unique application key for the Laravel project, which is used for encryption and security purposes. This command should be run after copying the .env file. ```bash php artisan key:generate ``` -------------------------------- ### Responsive Images with HTML srcset and sizes Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/performance.md Example of using HTML's `srcset` and `sizes` attributes to implement responsive images. This allows the browser to select the most appropriate image source based on screen size and resolution, optimizing image loading performance. It requires multiple image versions at different resolutions. ```html Description ``` -------------------------------- ### Manage Permissions with Shield and Custom Commands Source: https://context7.com/riodwanto/superduper-filament-starter-kit/llms.txt Utilizes Shield for permission management and includes custom Artisan commands for generating, binding, and refreshing permissions and roles. Demonstrates a role structure and examples of custom permissions for blog posts. ```bash # Generate all permissions and policies (Shield command) php artisan shield:generate --all # Bind permissions to roles (custom command) php artisan superduper:permissions # Regenerate permissions and re-seed roles php artisan superduper:permissions --fresh # Role structure after seeding: # - super_admin: All permissions # - panel_user: Basic panel access # - filament_user: Limited access # - editor: Content management # - author: Own content only # Custom post permissions: # - view_any_blog::post # - view_blog::post # - create_blog::post # - update_blog::post # - delete_blog::post # - delete_any_blog::post # - force_delete_blog::post # - force_delete_any_blog::post # - restore_blog::post # - restore_any_blog::post # - replicate_blog::post # - reorder_blog::post # - publish_blog::post # Custom # - archive_blog::post # Custom # - feature_blog::post # Custom # - change_author_blog::post # Custom # - approve_blog::post # Custom # - schedule_blog::post # Custom # - manage_seo_blog::post # Custom # - bulk_publish_blog::post # Custom # - view_analytics_blog::post # Custom ``` -------------------------------- ### Generate Shield Permissions and Seed Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/installation.md Generates necessary permissions for the Shield package and seeds the permissions table. This is crucial for role-based access control within the application. ```bash php artisan shield:generate --all php artisan db:seed --class=PermissionsSeeder ``` -------------------------------- ### Optimize Frontend Assets with NPM Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/performance.md Command to optimize frontend assets (CSS and JavaScript) for production using NPM scripts. This typically involves minification and concatenation, leading to smaller file sizes and faster page loads. Requires an NPM project setup with a 'production' script defined. ```bash npm run production ``` -------------------------------- ### JavaScript Banner Tracking Source: https://context7.com/riodwanto/superduper-filament-starter-kit/llms.txt This JavaScript snippet provides an example of how to implement client-side tracking for banner impressions and clicks. It shows how to use fetch API to send POST requests to the backend endpoints when a banner is displayed or clicked. ```javascript /*
*/ ``` -------------------------------- ### Run Laravel Queue Worker Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/performance.md Command to start a Laravel queue worker. Queue workers process background jobs asynchronously, improving application responsiveness by offloading time-consuming tasks. The `--tries` option specifies the number of times a failed job should be retried. ```bash # Start queue worker php artisan queue:work --tries=3 ``` -------------------------------- ### Run PHPUnit Tests (Bash) Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/development.md Executes PHPUnit tests for the application. Supports running all tests, specific tests using a filter, and generating HTML code coverage reports with XDebug. ```bash # Run all tests php artisan test # Run specific test php artisan test --filter=TestCaseName # Run with coverage (requires XDebug) XDEBUG_MODE=coverage php artisan test --coverage-html=coverage ``` -------------------------------- ### API Authentication with Laravel Sanctum (HTTP) Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/development.md Demonstrates how to obtain an API token using Laravel Sanctum by sending a POST request with user credentials and then how to use that token for subsequent authenticated API requests. ```http # Get a token POST /api/auth/login Content-Type: application/json { "email": "user@example.com", "password": "password" } # Use the token in subsequent requests GET /api/user Authorization: Bearer your-token-here ``` -------------------------------- ### Cache Application Configurations Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/performance.md Caches your application's configuration files into a single, cached file for faster loading. This is a common optimization technique in Laravel. It does not require any specific inputs and has no direct outputs other than improved performance. ```bash php artisan config:cache ``` -------------------------------- ### Cache Application Views Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/performance.md Pre-compiles all of your Blade views. This can lead to a significant performance improvement by eliminating the need to compile views on each request. It has no direct inputs or outputs beyond performance gains. ```bash php artisan view:cache ``` -------------------------------- ### Code Style Check and Fix (Bash) Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/development.md Utilizes Composer scripts to check the project's adherence to PSR-12 coding standards and to automatically fix any style violations. Ensures code consistency across the project. ```bash composer check-style composer fix-style ``` -------------------------------- ### Generate Filament Resource (Bash) Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/development.md A command-line interface command to generate a new Filament resource, including the necessary boilerplate for CRUD operations within the Filament admin panel. Requires manual registration in `AdminPanelProvider.php`. ```bash php artisan make:filament-resource ResourceName ``` -------------------------------- ### Cache Icons for Filament Performance Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/README.md This command caches Filament icons to improve the performance of your Filament panels. It's a recommended step for optimizing your application's frontend. No external dependencies are required beyond a standard Laravel/Filament installation. ```bash php artisan icons:cache ``` -------------------------------- ### Install Laravel Debugbar Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/performance.md Composer command to install Laravel Debugbar, a package that adds a data collector toolbar to your application's output. It provides quick access to logs, queries, views, and other debugging information directly in the browser. This is a development-only package. ```bash composer require barryvdh/laravel-debugbar --dev ``` -------------------------------- ### Manage Site Configuration with Laravel Settings Source: https://context7.com/riodwanto/superduper-filament-starter-kit/llms.txt Demonstrates how to manage various site configurations like brand details, theme colors, SEO settings, social media links, and mail settings using Spatie Laravel Settings. All settings are persisted to the database and cached for performance. ```php // General Settings (app/Settings/GeneralSettings.php) use App\Settings\GeneralSettings; $settings = app(GeneralSettings::class); // Brand configuration $settings->brand_name = 'My Awesome App'; $settings->brand_logo = '/storage/logo.png'; $settings->brand_logoHeight = '40px'; $settings->site_favicon = '/storage/favicon.ico'; // Theme colors (array of hex values) $settings->site_theme = [ 'primary' => '#3b82f6', 'secondary' => '#10b981', 'gray' => '#6b7280', 'success' => '#22c55e', 'danger' => '#ef4444', 'info' => '#3b82f6', 'warning' => '#f59e0b', ]; // Search engine indexing toggle $settings->search_engine_indexing = true; // Save all changes $settings->save(); // Site Settings (app/Settings/SiteSettings.php) use App\Settings\SiteSettings; $site = app(SiteSettings::class); $site->site_name = 'My Website'; $site->site_tagline = 'Building the future'; $site->site_description = 'A comprehensive platform...'; $site->maintenance_mode = false; $site->company_name = 'Acme Corp'; $site->company_email = 'info@acme.com'; $site->company_phone = '+1234567890'; $site->company_address = '123 Main St, City, Country'; $site->default_language = 'en'; $site->default_timezone = 'UTC'; $site->copyright_text = '© 2024 Acme Corp. All rights reserved.'; $site->terms_url = '/terms-conditions'; $site->privacy_url = '/privacy-policy'; $site->custom_404_message = 'Page not found'; $site->custom_500_message = 'Internal server error'; $site->save(); // Mail Settings (app/Settings/MailSettings.php) use App\Settings\MailSettings; $mail = app(MailSettings::class); $mail->mail_mailer = 'smtp'; $mail->mail_host = 'smtp.mailtrap.io'; $mail->mail_port = '2525'; $mail->mail_username = 'username'; $mail->mail_password = 'password'; $mail->mail_encryption = 'tls'; $mail->mail_from_address = 'noreply@example.com'; $mail->mail_from_name = 'My App'; $mail->save(); // SEO Settings (app/Settings/SiteSeoSettings.php) use App\Settings\SiteSeoSettings; $seo = app(SiteSeoSettings::class); $seo->meta_title = 'My Website - Building the Future'; $seo->meta_description = 'Comprehensive platform for...'; $seo->meta_keywords = 'laravel, filament, saas'; $seo->og_image = '/storage/og-image.jpg'; $seo->sitemap_enabled = true; $seo->robots_txt = "User-agent: *\nDisallow: /admin\nAllow: /"; $seo->save(); // Social Settings (app/Settings/SiteSocialSettings.php) use App\Settings\SiteSocialSettings; $social = app(SiteSocialSettings::class); $social->facebook_url = 'https://facebook.com/myapp'; $social->twitter_url = 'https://twitter.com/myapp'; $social->linkedin_url = 'https://linkedin.com/company/myapp'; $social->instagram_url = 'https://instagram.com/myapp'; $social->youtube_url = 'https://youtube.com/@myapp'; $social->save(); // All settings are automatically persisted to database // and cached for performance ``` -------------------------------- ### PHP File Service for Theme and Configuration Management Source: https://context7.com/riodwanto/superduper-filament-starter-kit/llms.txt Demonstrates the usage of a custom `FileService` for securely writing content to files, including theme CSS and Tailwind configuration. This service handles directory checks, permissions, atomic writes, and error handling. ```php // File Service (used in ManageGeneral settings page) // Location: app/Services/FileService.php use App\Services\FileService; $fileService = app(FileService::class); // Write theme CSS file $themePath = resource_path('css/filament/admin/theme.css'); $cssContent = " :root { --primary: 59 130 246; --secondary: 16 185 129; } .fi-sidebar { background-color: rgb(var(--primary)); } "; try { $fileService->writeFile($themePath, $cssContent); // File written successfully with proper permissions } catch (Exception $e) { // Handle write error } // Write Tailwind config $twConfigPath = base_path('tailwind.config.js'); $twConfig = " import preset from './vendor/filament/support/tailwind.config.preset' export default { presets: [preset], content: [ './app/Filament/**/*.php', './resources/views/**/*.blade.php', ], theme: { extend: { colors: { primary: '#3b82f6', } } } } "; $fileService->writeFile($twConfigPath, $twConfig); // File operations include: // - Directory existence check and creation // - Permission verification // - Atomic write with backup // - Error handling and logging ``` -------------------------------- ### User Creation, Roles, and Impersonation (PHP) Source: https://context7.com/riodwanto/superduper-filament-starter-kit/llms.txt Illustrates user management functionalities including creating users with avatars, assigning and checking roles, accessing display names and avatar URLs, managing panel access, and implementing super admin impersonation. Includes details on configuration and routes for impersonation. ```php // User Model (app/Models/User.php) use App\Models\User; use Lab404\Impersonate\Models\Impersonate; // Create user with avatar $user = User::create([ 'username' => 'johndoe', 'email' => 'john@example.com', 'firstname' => 'John', 'lastname' => 'Doe', 'password' => bcrypt('password'), ]); // Attach avatar with automatic conversion $user->addMedia($file)->toMediaCollection('avatars'); // Generates 300x300 thumbnail automatically // Assign roles (using Spatie Permission via Filament Shield) $user->assignRole('super_admin'); $user->assignRole(['editor', 'author']); // Check user role if ($user->isSuperAdmin()) { // Super admin specific logic } // Get Filament display name $displayName = $user->getFilamentName(); // Returns "John Doe" // Get avatar URL with fallback to ui-avatars.com $avatarUrl = $user->getFilamentAvatarUrl(); // Returns: https://ui-avatars.com/api/?name=John+Doe&color=... // Or actual avatar if uploaded // Check panel access $canAccess = $user->canAccessPanel($panel); // Boolean // Impersonation (Super Admin only) if (auth()->user()->canImpersonate() && $targetUser->canBeImpersonated()) { auth()->user()->impersonate($targetUser); // Session tracks 'impersonate.back_to' URL } // Leave impersonation auth()->user()->leaveImpersonation(); // Redirects to stored 'impersonate.back_to' URL // Route for leaving impersonation (routes/web.php) // GET /impersonate/leave // Impersonation configuration (config/superduper.php) /* 'impersonate' => [ 'back_to_session_key' => 'impersonate.back_to', 'can_impersonate_method' => 'canImpersonate', 'can_be_impersonated_method' => 'canBeImpersonated', ] */ // Email verification $user->sendEmailVerificationNotification(); $isVerified = $user->hasVerifiedEmail(); ``` -------------------------------- ### Custom Theme Stylesheet (CSS) Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/development.md Defines custom styles for the Filament theme, overriding default styles using Tailwind CSS directives. This example targets the sidebar to change its background and text color. ```css @config "../../tailwind.config.js"; @tailwind base; @tailwind components; @tailwind utilities; /* Custom styles */ .fi-sidebar { @apply bg-primary-600 text-white; } ``` -------------------------------- ### Caching Configuration for Production Environment Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/configuration.md Sets up caching for production environments, recommending a 'redis' driver. Includes details for Redis connection such as client, host, password, and port. This improves performance by reducing database load. ```env CACHE_DRIVER=redis REDIS_CLIENT=predis REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379 ``` -------------------------------- ### PHP Banner Management: Creation, Tracking, and Scheduling Source: https://context7.com/riodwanto/superduper-filament-starter-kit/llms.txt This snippet illustrates the creation of banners with scheduling capabilities, attaching images, tracking impressions and clicks, calculating CTR, and retrieving image URLs with conversions. It also shows how to query active banners and details the corresponding API endpoints. ```php // Banner Model (app/Models/Banner/Content.php) use App\Models\Banner\Content; // Create banner with scheduling $banner = Content::create([ 'banner_category_id' => 1, 'title' => 'Summer Sale 2024', 'description' => 'Get 50% off on all products', 'click_url' => 'https://example.com/summer-sale', 'click_url_target' => '_blank', 'is_active' => true, 'start_date' => now(), 'end_date' => now()->addDays(30), 'published_at' => now(), 'locale' => 'en', 'sort' => 1, ]); // Attach banner image (recommended: 1200x800px) $banner->addMedia($file)->toMediaCollection('banner-image'); // Track impressions (when banner is displayed) $banner->trackImpression(); // Increments impression_count // Track clicks (when user clicks banner) $banner->trackClick(); // Increments click_count // Calculate Click-Through Rate $impressions = $banner->impression_count; // e.g., 1000 $clicks = $banner->click_count; // e.g., 45 $ctr = ($impressions > 0) ? ($clicks / $impressions) * 100 : 0; // Result: 4.5% CTR // Get image URL with conversion $imageUrl = $banner->getImageUrl('large'); // Returns WebP optimized URL $hasImage = $banner->hasImage(); // Boolean check // Query active banners (within date range and is_active=true) $activeBanners = Content::active()->get(); // API endpoints for tracking (routes/api.php) // POST /api/banners/{banner}/impression // POST /api/banners/{banner}/click // Both return: {"success": true} ``` -------------------------------- ### PHP Blog Post Management: Status, Creation, and Tracking Source: https://context7.com/riodwanto/superduper-filament-starter-kit/llms.txt This snippet demonstrates the PostStatus enum, creating a new blog post with various attributes, tracking views, retrieving related posts, generating social media share URLs, navigating between posts, and using scopes for filtering. It also outlines custom permissions and media conversion URLs. ```php // Post Status Workflow (app/Enums/Blog/PostStatus.php) enum PostStatus: string { case DRAFT = 'draft'; // Authors can create case PENDING = 'pending'; // Submitted for review case PUBLISHED = 'published'; // Only editors/admins can publish case ARCHIVED = 'archived'; // Archived content } // Post Model Methods (app/Models/Blog/Post.php) $post = Post::create([ 'blog_author_id' => auth()->id(), 'blog_category_id' => 1, 'title' => 'Getting Started with Laravel', 'content_raw' => '# Introduction\n\nLaravel is amazing...', 'status' => PostStatus::DRAFT, 'is_featured' => false, 'published_at' => now(), ]); // Auto-calculated fields: // - slug: Auto-generated from title (editable via suffix action) // - content_html: Markdown -> HTML with GithubFlavoredMarkdownConverter // - reading_time: Calculated as word_count / 200 (average reading speed) // Track post views $post->trackView(); // Increments view_count // Get related posts by category and tags $relatedPosts = $post->getRelatedPosts($limit = 3); // Social media sharing URLs $twitterUrl = $post->getTwitterShareUrl(); $facebookUrl = $post->getFacebookShareUrl(); $linkedinUrl = $post->getLinkedinShareUrl(); // Post navigation $previousPost = $post->getPreviousPost(); $nextPost = $post->getNextPost(); // Scopes for filtering $publishedPosts = Post::published()->get(); // Published & not future-dated $featuredPosts = Post::featured()->get(); $draftPosts = Post::byStatus(PostStatus::DRAFT)->get(); $frenchPosts = Post::locale('fr')->get(); // Custom permissions for granular access control: // 'publish', 'archive', 'feature', 'change_author', 'approve', // 'schedule', 'manage_seo', 'bulk_publish', 'view_analytics' // Media conversions (automatic WebP optimization): $post->getFirstMediaUrl('featured_image', 'preview'); // 300x300 $post->getFirstMediaUrl('featured_image', 'thumbnail'); // 150x150 $post->getFirstMediaUrl('featured_image', 'medium'); // 600x600 $post->getFirstMediaUrl('featured_image', 'large'); // 1200x800 ``` -------------------------------- ### Cache Application Routes Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/performance.md Caches your application's routes. This speeds up route registration, especially for applications with a large number of routes. No specific inputs are required, and the output is faster route matching. ```bash php artisan route:cache ``` -------------------------------- ### Media Library Integration with Spatie Media Library in PHP Source: https://context7.com/riodwanto/superduper-filament-starter-kit/llms.txt This integration leverages Spatie Media Library to manage media attachments for any model, including automatic WebP conversions and responsive image generation. It requires implementing the HasMedia interface and configuring media conversions. The library provides methods for uploading, retrieving, and deleting media. ```php // All models with images (Posts, Banners, Users, etc.) use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; class Post extends Model implements HasMedia { use InteractsWithMedia; // Standard conversions applied automatically public function registerMediaConversions(Media|null $media = null): void { $this->addMediaConversion('preview') ->format('webp') ->quality(90) ->fit(Fit::Contain, 300, 300) ->nonQueued(); $this->addMediaConversion('thumbnail') ->format('webp') ->quality(85) ->fit(Fit::Contain, 150, 150) ->nonQueued(); $this->addMediaConversion('medium') ->format('webp') ->quality(85) ->fit(Fit::Contain, 600, 600) ->nonQueued(); $this->addMediaConversion('large') ->format('webp') ->quality(85) ->fit(Fit::Contain, 1200, 800) ->nonQueued(); } } // Upload file $post->addMedia($request->file('image')) ->toMediaCollection('featured_image'); // Get image URLs $originalUrl = $post->getFirstMediaUrl('featured_image'); $previewUrl = $post->getFirstMediaUrl('featured_image', 'preview'); $thumbnailUrl = $post->getFirstMediaUrl('featured_image', 'thumbnail'); $mediumUrl = $post->getFirstMediaUrl('featured_image', 'medium'); $largeUrl = $post->getFirstMediaUrl('featured_image', 'large'); // Get all media items $media = $post->getMedia('featured_image'); // Check if media exists $hasMedia = $post->hasMedia('featured_image'); // Delete media $post->clearMediaCollection('featured_image'); // Update media custom properties $mediaItem = $post->getFirstMedia('featured_image'); $mediaItem->setCustomProperty('alt_text', 'Descriptive text'); $mediaItem->save(); // Responsive images (automatic generation) $responsiveImages = $mediaItem->responsive_images; ``` -------------------------------- ### Web Routes Source: https://context7.com/riodwanto/superduper-filament-starter-kit/llms.txt Defines the public-facing routes for the application, including homepage, about, blog, contact, legal pages, and SEO endpoints. ```APIDOC ## Web Routes ### Description Provides access to various public pages and functionalities of the application. ### Method GET, POST ### Endpoints - `/` - Homepage - `/about-us` - About Us page - `/blog` - Blog listing page - `/blog/{slug}` - Specific blog post details - `/contact-us` - Contact Us form page - `/contact` - Submits the contact form - `/privacy-policy` - Privacy Policy page - `/terms-conditions` - Terms and Conditions page - `/impersonate/leave` - Leaves impersonation mode - `/sitemap.xml` - Generates the sitemap - `/robots.txt` - Robots.txt file ### Parameters #### Path Parameters - **slug** (string) - Required - The unique identifier for a blog post. #### Query Parameters None #### Request Body For `/contact` POST request: - **name** (string) - Required - The name of the contact person. - **email** (string) - Required - The email address of the contact person. - **message** (string) - Required - The message content. ### Request Example ```http POST /contact Content-Type: application/json { "name": "John Doe", "email": "john.doe@example.com", "message": "This is a test message." } ``` ### Response #### Success Response (200) - Varies based on the route accessed. For contact submission, typically a redirect or a success message. #### Response Example ```json { "message": "Contact form submitted successfully." } ``` ``` -------------------------------- ### Environment Variables for Application Settings Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/configuration.md Sets up core application parameters including name, environment, debug mode, and URL. These variables are crucial for the application's basic functionality and accessibility. ```env APP_NAME="SuperDuper Filament Starter Kit" APP_ENV=local APP_DEBUG=true APP_URL=http://localhost:8000 ``` -------------------------------- ### Seeding Permissions (Bash) Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/README.md Command to seed specific permission classes into the database, essential for binding permissions to roles. ```bash php artisan db:seed --class=PermissionsSeeder ``` -------------------------------- ### Clear All Application Caches Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/performance.md Clears all cached data, including configuration, routes, views, and application cache. This is useful when changes are made that are not reflected due to caching. It does not take specific inputs and its output is a cleared cache. ```bash php artisan optimize:clear ``` -------------------------------- ### Contact Form Creation and Management (PHP) Source: https://context7.com/riodwanto/superduper-filament-starter-kit/llms.txt Demonstrates how to create, update, and manage contact form submissions using the ContactUs model. It includes methods for marking as read, adding replies, searching, filtering by status, and accessing tracking information. Handles status transitions automatically. ```php // Contact Us Model (app/Models/ContactUs.php) use App\Models\ContactUs; // Create contact submission (typically from web form) $contact = ContactUs::create([ 'firstname' => 'John', 'lastname' => 'Doe', 'email' => 'john@example.com', 'phone' => '+1234567890', 'company' => 'Acme Inc', 'employees' => '50-100', 'title' => 'CEO', 'subject' => 'Partnership Inquiry', 'message' => 'I am interested in partnering with your company...', 'status' => 'new', // new, read, pending, responded, closed 'ip_address' => request()->ip(), 'user_agent' => request()->userAgent(), 'metadata' => [ 'utm_source' => 'google', 'utm_medium' => 'cpc', 'utm_campaign' => 'spring2024', ], ]); // Event dispatched automatically on creation // App\Events\ContactUsCreated is fired for notifications // Mark message as read $contact->markAsRead(); // Sets status to 'read' // Add reply to contact $contact->addReply( subject: 'Re: Partnership Inquiry', message: 'Thank you for your interest. We would love to discuss...', user: auth()->user() ); // Automatically sets: // - status to 'responded' // - reply_subject, reply_message // - replied_at timestamp // - replied_by_user_id // Get full name $fullName = $contact->name; // Returns "John Doe" // Search contacts (fulltext search on MySQL, LIKE fallback) $results = ContactUs::search('partnership')->get(); // Filter by status with visual indicators $newContacts = ContactUs::where('status', 'new')->get(); // Red border in UI $readContacts = ContactUs::where('status', 'read')->get(); // Yellow border $responded = ContactUs::where('status', 'responded')->get(); // Green border // Access tracking information (admin only visibility) $ipAddress = $contact->ip_address; // Hidden by default $userAgent = $contact->user_agent; // Hidden by default // Bulk operations ContactUs::whereIn('id', $contactIds)->update(['status' => 'read']); ``` -------------------------------- ### API Routes Source: https://context7.com/riodwanto/superduper-filament-starter-kit/llms.txt Defines API endpoints for user authentication and banner tracking. ```APIDOC ## API Routes ### Description Provides API endpoints for user data retrieval and banner interaction tracking. ### Method GET, POST ### Endpoints - `/user` - Retrieves authenticated user data. - `/banners/{banner}/impression` - Tracks a banner impression. - `/banners/{banner}/click` - Tracks a banner click. ### Parameters #### Path Parameters - **banner** (Content) - Required - The specific banner object. #### Query Parameters None #### Request Body None for these endpoints. ### Request Example ```http POST /banners/1/impression Content-Type: application/json {} // Empty body ``` ### Response #### Success Response (200) - `/user`: Returns the authenticated user object. - `/banners/{banner}/impression`, `/banners/{banner}/click`: Returns a JSON object indicating success. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### PHP Web Routes for Public Pages and Features Source: https://context7.com/riodwanto/superduper-filament-starter-kit/llms.txt Defines the web routes for various public-facing pages including the homepage, about page, blog, contact form, legal pages, impersonation functionality, and SEO endpoints. It utilizes Blade views and Livewire components for rendering content. ```php // Web Routes (routes/web.php) // Homepage Route::get('/', function() { return view('components.superduper.pages.home'); })->name('home'); // About page Route::get('/about-us', function() { return view('components.superduper.pages.about'); })->name('about-us'); // Blog (Livewire components) Route::get('/blog', \App\Livewire\Blog\BlogList::class)->name('blog'); Route::get('/blog/{slug}', \App\Livewire\Blog\BlogDetails::class)->name('blog.show'); // Contact Us Route::get('/contact-us', \App\Livewire\ContactUs::class)->name('contact-us'); Route::post('/contact', [ContactController::class, 'submit'])->name('contact.submit'); // Legal pages Route::get('/privacy-policy', function() { return view('components.superduper.pages.coming-soon'); })->name('privacy-policy'); Route::get('/terms-conditions', function() { return view('components.superduper.pages.coming-soon'); })->name('terms-conditions'); // Impersonation leave route Route::get('impersonate/leave', function() { if (!app(ImpersonateManager::class)->isImpersonating()) { return redirect('/'); } app(ImpersonateManager::class)->leave(); return redirect(session()->pull('impersonate.back_to')); })->name('impersonate.leave')->middleware('web'); // SEO Route::get('/sitemap.xml', [SitemapController::class, 'index'])->name('sitemap'); Route::get('/robots.txt', [SitemapController::class, 'robots'])->name('robots'); ``` -------------------------------- ### PHP API Routes for User and Banner Endpoints Source: https://context7.com/riodwanto/superduper-filament-starter-kit/llms.txt Sets up API routes for user authentication using Sanctum and for tracking banner impressions and clicks. These routes are designed to be consumed by external clients or frontend applications. ```php // API Routes (routes/api.php) // User authentication Route::middleware('auth:sanctum')->get('/user', function (Request $request) { return $request->user(); }); // Banner tracking endpoints Route::post('/banners/{banner}/impression', function (Content $banner) { $banner->trackImpression(); return response()->json(['success' => true]); }); Route::post('/banners/{banner}/click', function (Content $banner) { $banner->trackClick(); return response()->json(['success' => true]); }); ``` -------------------------------- ### Environment Variables for Cache and Session Drivers Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/configuration.md Specifies the drivers for caching and session management, along with session lifetime. 'file' is a common default, but can be changed for production environments. ```env CACHE_DRIVER=file SESSION_DRIVER=file SESSION_LIFETIME=120 ``` -------------------------------- ### Troubleshoot Database Connection Issues Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/commands.md Resolves database connection problems after modifying the `.env` file. It requires clearing the configuration cache to ensure the updated environment variables are loaded. Subsequently, running migrations is necessary to apply any pending database schema changes. ```bash php artisan config:clear php artisan migrate ``` -------------------------------- ### Optimize Eloquent Count Queries Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/performance.md Shows how to optimize counting records in Laravel Eloquent. Instead of fetching all records and then counting, use the `count()` method directly on the Eloquent query builder for much better performance. This avoids unnecessary data retrieval. ```php // Instead of Post::all()->count(); // Use Post::count(); ``` -------------------------------- ### Configure PHP-FPM Pool Settings Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/performance.md Configuration snippet for PHP-FPM's `www.conf` file, adjusting process manager settings. Tuning `pm`, `pm.max_children`, `pm.start_servers`, `pm.min_spare_servers`, and `pm.max_spare_servers` can optimize PHP request handling and resource usage. This requires editing the PHP-FPM configuration file. ```ini pm = dynamic pm.max_children = 25 pm.start_servers = 5 pm.min_spare_servers = 2 pm.max_spare_servers = 10 ``` -------------------------------- ### File Management Service Source: https://context7.com/riodwanto/superduper-filament-starter-kit/llms.txt Details the custom file service for managing theme and configuration files with built-in validation and error handling. ```APIDOC ## File Management Service ### Description A custom service for safely writing and managing files, including theme and configuration files, with robust error handling and atomic operations. ### Method Uses internal methods for file operations. ### Endpoints This is a service class, not a direct endpoint. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body Not applicable. ### Request Example ```php // Write theme CSS file $fileService = app(FileService::class); $themePath = resource_path('css/filament/admin/theme.css'); $cssContent = ":root { --primary: 59 130 246; --secondary: 16 185 129; } .fi-sidebar { background-color: rgb(var(--primary)); } "; try { $fileService->writeFile($themePath, $cssContent); // File written successfully } catch (\Exception $e) { // Handle write error } // Write Tailwind config $twConfigPath = base_path('tailwind.config.js'); $twConfig = "import preset from './vendor/filament/support/tailwind.config.preset' export default { presets: [preset], content: [ './app/Filament/**/*.php', './resources/views/**/*.blade.php', ], theme: { extend: { colors: { primary: '#3b82f6', } } } }"; $fileService->writeFile($twConfigPath, $twConfig); ``` ### Response #### Success Response File operations complete without exceptions. #### Response Example No direct response, but exceptions are thrown on failure. The service internally handles directory creation, permission checks, atomic writes with backups, and error logging. ``` -------------------------------- ### Add Database Indexes in Migrations Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/performance.md Demonstrates how to add database indexes to columns within a Laravel migration. Proper indexing significantly improves the performance of database queries, especially on frequently queried columns like 'slug' and 'published_at'. This code snippet requires a database schema definition. ```php // In your migration public function up() { Schema::table('posts', function (Blueprint $table) { $table->index('slug'); $table->index('published_at'); }); } ``` -------------------------------- ### Application Localization Settings Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/configuration.md Configures the default and fallback locales for the application, and lists the available locales. This is defined in `config/app.php` and supports multi-language applications. ```php 'locale' => 'en', 'fallback_locale' => 'en', 'available_locales' => [ 'en' => 'English', 'es' => 'Spanish', 'fr' => 'French', ], ``` -------------------------------- ### Eager Loading Relationships in Laravel Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/performance.md Illustrates the difference between naive collection iteration and eager loading of relationships in Laravel Eloquent. Eager loading prevents the N+1 query problem, significantly improving database performance when accessing related data. It takes a collection of models as input and provides optimized data retrieval. ```php // Instead of $posts = Post::all(); foreach ($posts as $post) { echo $post->author->name; } // Use eager loading $posts = Post::with('author')->get(); ``` -------------------------------- ### Configure Nginx for Gzip Compression and Asset Caching Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/performance.md Nginx configuration directives to enable gzip compression for text-based assets and set long expiration times for static assets (images, JS, CSS). This reduces bandwidth usage and improves loading speed by leveraging browser caching. Requires Nginx server block configuration. ```nginx # Enable gzip gzip on; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; # Enable caching location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff2|woff|ttf|svg|eot)$ { expires 30d; add_header Cache-Control "public, no-transform"; } ``` -------------------------------- ### Filament Shield Permissions Generation (Bash) Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/README.md Command to generate all permissions and policies for Filament Shield, ensuring comprehensive role-based access control. ```bash php artisan shield:generate --all ``` -------------------------------- ### Environment Variables for Mail Configuration Source: https://github.com/riodwanto/superduper-filament-starter-kit/blob/master/resources/docs/en/configuration.md Defines settings for the mailer, including the driver, host, port, authentication credentials, encryption, and sender address/name. Used for sending emails from the application. ```env MAIL_MAILER=smtp MAIL_HOST=mailhog MAIL_PORT=1025 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null MAIL_FROM_ADDRESS="hello@example.com" MAIL_FROM_NAME="${APP_NAME}" ```