### Install Frontend Dependencies and Start Server Source: https://laravel.com/docs/master/starter-kits After creating the application, install its frontend dependencies via NPM and start the Laravel development server. Ensure you are in the application's root directory. ```shell cd my-app npm install && npm run build composer run dev ``` -------------------------------- ### Run Laravel Boost Installer Source: https://laravel.com/docs/master/ai After installation, run the Artisan command to initiate the Boost setup. This interactive installer helps configure IDE and AI agent integrations. ```shell php artisan boost:install ``` -------------------------------- ### Install Dusk and ChromeDriver Source: https://laravel.com/docs/master/dusk Run the dusk:install Artisan command to set up the tests directory, an example test, and install the ChromeDriver binary. ```shell php artisan dusk:install ``` -------------------------------- ### Start Laravel Development Server Source: https://laravel.com/docs/master/installation After creating an application, navigate into the project directory and run these commands to install dependencies, build assets, and start the development server using Composer scripts. ```shell cd example-app npm install && npm run build composer run dev ``` -------------------------------- ### Installation Source: https://laravel.com/docs/master/prompts Instructions on how to install the Laravel Prompts package. ```APIDOC ## Installation Laravel Prompts is already included with the latest release of Laravel. Laravel Prompts may also be installed in your other PHP projects by using the Composer package manager: ```shell composer require laravel/prompts ``` ``` -------------------------------- ### Install PHP, Composer, and Laravel Installer on Linux Source: https://laravel.com/docs/master/installation Run this command to install PHP, Composer, and the Laravel installer on Linux. A terminal restart is recommended after execution. ```shell /bin/bash -c "$(curl -fsSL https://php.new/install/linux/8.4)" ``` -------------------------------- ### Database URL Configuration Examples Source: https://laravel.com/docs/master/database Examples of database connection strings and their standard schema format. ```html mysql://root:password@127.0.0.1/forge?charset=UTF-8 ``` ```html driver://username:password@host:port/database?options ``` -------------------------------- ### Install Packages Avoiding Configuration Prompts Source: https://laravel.com/docs/master/homestead Use this command to install packages in a non-interactive way, preventing prompts about overwriting configuration files. This is useful for automated setup scripts. ```shell sudo apt-get -y \ -o Dpkg::Options::="--force-confdef" \ -o Dpkg::Options::="--force-confold" \ install package-name ``` -------------------------------- ### Define a Route Interacting with an Asynchronous Process Source: https://laravel.com/docs/master/processes This example shows a typical route that starts an asynchronous process and logs its output while it's running. It requires importing the Route facade. ```php use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Route; Route::get('/import', function () { $process = Process::start('bash import.sh'); while ($process->running()) { Log::info($process->latestOutput()); Log::info($process->latestErrorOutput()); } return 'Done'; }); ``` -------------------------------- ### Install Stream Packages Source: https://laravel.com/docs/master/responses Install the required package for your frontend framework. ```shell npm install @laravel/stream-react ``` ```shell npm install @laravel/stream-vue ``` -------------------------------- ### Install Laravel via php.new Source: https://laravel.com/docs/master/upgrade Commands to install the latest PHP and Laravel installer for different operating systems. ```macOS /bin/bash -c "$(curl -fsSL https://php.new/install/mac/8.4)" ``` ```Windows PowerShell # Run as administrator... Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://php.new/install/windows/8.4')) ``` ```Linux /bin/bash -c "$(curl -fsSL https://php.new/install/linux/8.4)" ``` -------------------------------- ### Install Community Starter Kit Source: https://laravel.com/docs/master/starter-kits Use the --using flag with the Laravel installer to scaffold an application from a Packagist package. ```shell laravel new my-app --using=example/starter-kit ``` -------------------------------- ### Install Laravel Installer via Composer Source: https://laravel.com/docs/master/installation If PHP and Composer are already installed, use this command to globally install the Laravel installer. This is an alternative to using the `php.new` script. ```shell composer global require laravel/installer ``` -------------------------------- ### Install Frontend Dependencies Source: https://laravel.com/docs/master/vite Install the project's frontend dependencies defined in package.json. ```shell npm install ``` -------------------------------- ### Install Typesense SDK Source: https://laravel.com/docs/master/scout Install the Typesense PHP SDK via Composer. ```shell composer require typesense/typesense-php ``` -------------------------------- ### Install PHP, Composer, and Laravel Installer on Windows Source: https://laravel.com/docs/master/installation Execute this PowerShell command as administrator to install PHP, Composer, and the Laravel installer on Windows. It sets the execution policy and downloads the installer. ```powershell # Run as administrator... Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://php.new/install/windows/8.4')) ``` -------------------------------- ### Manually Install Reverb Source: https://laravel.com/docs/master/broadcasting Installs the Reverb package via Composer and runs the installation command to configure the environment. ```shell composer require laravel/reverb ``` ```shell php artisan reverb:install ``` -------------------------------- ### Install PHP with Homebrew Source: https://laravel.com/docs/master/valet Install PHP using Homebrew, a prerequisite for Valet. Ensure Homebrew is updated first. ```shell brew install php ``` -------------------------------- ### Install Resend PHP SDK Source: https://laravel.com/docs/master/mail Install the Resend PHP SDK using Composer. ```shell composer require resend/resend-php ``` -------------------------------- ### Install Postmark Mailer Source: https://laravel.com/docs/master/mail Install the Postmark Mailer transport and HTTP client using Composer. ```shell composer require symfony/postmark-mailer symfony/http-client ``` -------------------------------- ### Start Tailing Logs with Pail Source: https://laravel.com/docs/master/logging Run the 'pail' Artisan command to start tailing application logs in real time. ```shell php artisan pail ``` -------------------------------- ### Start Octane with Custom Caddyfile Source: https://laravel.com/docs/master/octane Specify a custom Caddyfile configuration when starting the Octane server. ```shell php artisan octane:start --server=frankenphp --caddyfile=/path/to/your/Caddyfile ``` -------------------------------- ### Install Ably PHP SDK Source: https://laravel.com/docs/master/broadcasting Use Composer to manually install the Ably PHP SDK. ```shell composer require ably/ably-php ``` -------------------------------- ### Install Precognition Alpine Helpers Source: https://laravel.com/docs/master/precognition Install the necessary frontend package via NPM. ```shell npm install laravel-precognition-alpine ``` -------------------------------- ### Install Open Swoole Extension Source: https://laravel.com/docs/master/octane Install the Open Swoole PHP extension using PECL. ```shell pecl install openswoole ``` -------------------------------- ### Install Ably via Artisan Source: https://laravel.com/docs/master/broadcasting Automatically install Ably SDKs and configure credentials using the Artisan command. ```shell php artisan install:broadcasting --ably ``` -------------------------------- ### Install Laravel Pennant Source: https://laravel.com/docs/master/pennant Commands to install the package, publish configuration, and run migrations. ```shell composer require laravel/pennant ``` ```shell php artisan vendor:publish --provider="Laravel\Pennant\PennantServiceProvider" ``` ```shell php artisan migrate ``` -------------------------------- ### Install Precognition Frontend Helpers Source: https://laravel.com/docs/master/precognition Install the necessary NPM package for Vue integration. ```shell npm install laravel-precognition-vue ``` -------------------------------- ### Start string with value using Str::start Source: https://laravel.com/docs/master/strings Ensures a string starts with the specified value, adding it only if missing. ```php use Illuminate\\Support\\Str; $adjusted = Str::start('this/string', '/'); // /this/string $adjusted = Str::start('/this/string', '/'); // /this/string ``` -------------------------------- ### Install @laravel/stream-react Source: https://laravel.com/docs/master/responses Install the React package for consuming Laravel event streams. ```shell npm install @laravel/stream-react ``` -------------------------------- ### Basic Controller Example Source: https://laravel.com/docs/master/controllers A basic controller with a public method to handle a specific route. This example shows how to fetch a user and return a view. ```php User::findOrFail($id) ]); } } ``` -------------------------------- ### Envoy Setup Script Source: https://laravel.com/docs/master/envoy Use the @setup directive to define a block of PHP code that executes before Envoy tasks. ```php @setup $now = new DateTime; @endsetup ``` -------------------------------- ### View Creation with Facade and Helper Source: https://laravel.com/docs/master/facades Demonstrates equivalent ways to create a view using the View facade and the view helper function. ```php return Illuminate\Support\Facades\View::make('profile'); ``` ```php return view('profile'); ``` -------------------------------- ### Install Laravel Folio Source: https://laravel.com/docs/master/folio Use Composer to install the package and the Artisan command to set up the service provider. ```shell composer require laravel/folio ``` ```shell php artisan folio:install ``` -------------------------------- ### Verify Node and NPM Installation Source: https://laravel.com/docs/master/vite Check the installed versions of Node.js and NPM to ensure compatibility. ```shell node -v npm -v ``` ```shell ./vendor/bin/sail node -v ./vendor/bin/sail npm -v ``` -------------------------------- ### Start the Reverb Server Source: https://laravel.com/docs/master/reverb Starts the Reverb server process. Use options to specify custom host and port configurations. ```shell php artisan reverb:start ``` ```shell php artisan reverb:start --host=127.0.0.1 --port=9000 ``` -------------------------------- ### Basic Pest Test Example Source: https://laravel.com/docs/master/testing A simple Pest test case that asserts a boolean value. Ensure Pest is installed and configured for your project. ```php toBeTrue(); }); ``` -------------------------------- ### Install Valet and Configure Services Source: https://laravel.com/docs/master/valet Execute the Valet install command to configure Valet and DnsMasq. This command also sets up Valet's required daemons to launch on system startup. ```shell valet install ``` -------------------------------- ### Setting Up Database Queue Driver Source: https://laravel.com/docs/master/queues Commands to generate the necessary database table for the database queue driver and apply the migration. ```shell php artisan make:queue-table php artisan migrate ``` -------------------------------- ### Retrieve All Users Source: https://laravel.com/docs/master/queries Use the DB facade's table method to start a query and the get method to retrieve all records from the 'users' table. Results are returned as a collection of stdClass objects. ```php get(); return view('user.index', ['users' => $users]); } } ``` -------------------------------- ### Install Meilisearch SDK Source: https://laravel.com/docs/master/scout Install the required Meilisearch PHP SDK and HTTP factory dependencies via Composer. ```shell composer require meilisearch/meilisearch-php http-interop/http-factory-guzzle ``` -------------------------------- ### Multi-search with Placeholder and Hint Source: https://laravel.com/docs/master/prompts Add placeholder text and an informational hint to the `multisearch` prompt to guide user input and provide context. The placeholder suggests an example input, and the hint offers additional information. ```php $ids = multisearch( label: 'Search for the users that should receive the mail', placeholder: 'E.g. Taylor Otwell', options: fn (string $value) => strlen($value) > 0 ? User::whereLike('name', "%{$value}%")->pluck('name', 'id')->all() : [], hint: 'The user will receive an email immediately.' ); ``` -------------------------------- ### Display Application Configuration Overview Source: https://laravel.com/docs/master/configuration Use the about command to view a summary of the application's environment and configuration drivers. ```shell php artisan about ``` -------------------------------- ### Install PHP, Composer, and Laravel Installer on macOS Source: https://laravel.com/docs/master/installation Use this command to install PHP, Composer, and the Laravel installer on macOS. Ensure you restart your terminal after installation. ```shell /bin/bash -c "$(curl -fsSL https://php.new/install/mac/8.4)" ``` -------------------------------- ### Show Database Overview Source: https://laravel.com/docs/master/database Use `db:show` to get an overview of your database, including size, type, and table summaries. Specify a connection with `--database` and include counts or views with respective flags. ```shell php artisan db:show ``` ```shell php artisan db:show --database=pgsql ``` ```shell php artisan db:show --counts --views ``` -------------------------------- ### Install Laravel Pulse Source: https://laravel.com/docs/master/pulse Install the Laravel Pulse package using Composer. This is the first step in setting up Pulse. ```shell composer require laravel/pulse ``` -------------------------------- ### Start Octane Server Source: https://laravel.com/docs/master/octane Use the octane:start Artisan command to launch your Octane server. It defaults to port 8000. ```shell php artisan octane:start ``` -------------------------------- ### Create Setup Intent in Controller Source: https://laravel.com/docs/master/billing Invoke the createSetupIntent method from the Billable trait to prepare for payment method collection. ```php return view('update-payment-method', [ 'intent' => $user->createSetupIntent() ]); ``` -------------------------------- ### Configure FTP Filesystem Source: https://laravel.com/docs/master/filesystem Example configuration for an FTP filesystem disk in config/filesystems.php. Use environment variables for credentials. ```php 'ftp' => [ 'driver' => 'ftp', 'host' => env('FTP_HOST'), 'username' => env('FTP_USERNAME'), 'password' => env('FTP_PASSWORD'), // Optional FTP Settings... // 'port' => env('FTP_PORT', 21), // 'root' => env('FTP_ROOT'), // 'passive' => true, // 'ssl' => true, // 'timeout' => 30, ], ``` -------------------------------- ### Install Laravel Cashier Source: https://laravel.com/docs/master/billing Install Laravel Cashier using Composer. This command will download and install the package. ```bash composer require laravel/cashier ``` -------------------------------- ### Install Laravel Prompts Source: https://laravel.com/docs/master/prompts Use Composer to add the package to any PHP project. ```shell composer require laravel/prompts ``` -------------------------------- ### Install Laravel Telescope Source: https://laravel.com/docs/master/telescope Use Composer to install Telescope into your Laravel project. This command installs the package and its dependencies. ```shell composer require laravel/telescope ``` -------------------------------- ### Run AI SDK Migrations Source: https://laravel.com/docs/master/ai-sdk Create the necessary database tables for conversation storage. ```shell php artisan migrate ``` -------------------------------- ### Build and Start SSR Server Source: https://laravel.com/docs/master/vite Run 'npm run build' to build your assets and SSR entry point, then start the SSR server using 'node bootstrap/ssr/ssr.js'. ```shell npm run build node bootstrap/ssr/ssr.js ``` -------------------------------- ### Install Laravel MongoDB Package Source: https://laravel.com/docs/master/mongodb Use Composer to install the official Laravel MongoDB package. Ensure the mongodb PHP extension is installed. ```shell composer require mongodb/laravel-mongodb ``` -------------------------------- ### Setting Up Job Batching Tables Source: https://laravel.com/docs/master/queues Generate and run the necessary database migrations to store job batch metadata. ```shell php artisan make:queue-batches-table php artisan migrate ``` -------------------------------- ### Make a GET Request Source: https://laravel.com/docs/master/http-client Use the `get` method to make a basic GET request to a specified URL. Ensure the `Http` facade is imported. ```php use Illuminate\Support\Facades\Http; $response = Http::get('http://example.com'); ``` -------------------------------- ### Start SSR Server with Artisan Source: https://laravel.com/docs/master/vite If using SSR with Inertia, you can start the SSR server using the 'php artisan inertia:start-ssr' command. ```shell php artisan inertia:start-ssr ``` -------------------------------- ### Publish Assets and Run Migrations Source: https://laravel.com/docs/master/telescope After installing Telescope, publish its assets and migrations using the `telescope:install` Artisan command, followed by the `migrate` command to create necessary database tables. ```shell php artisan telescope:install php artisan migrate ``` -------------------------------- ### MCP Server Class Example Source: https://laravel.com/docs/master/mcp Example of a basic MCP server class, extending Laravel\Mcp\Server and using attributes for configuration. ```php > */ protected array $tools = [ // GetCurrentWeatherTool::class, ]; /** * The resources registered with this MCP server. * * @var array> */ protected array $resources = [ // WeatherGuidelinesResource::class, ]; /** * The prompts registered with this MCP server. * * @var array> */ protected array $prompts = [ // DescribeWeatherPrompt::class, ]; } ``` -------------------------------- ### Get Application Directory Path Source: https://laravel.com/docs/master/helpers Use `app_path()` to get the path to the application directory. Provide a relative path to get a file within the app directory. ```php $path = app_path(); ``` ```php $path = app_path('Http/Controllers/Controller.php'); ``` -------------------------------- ### Apply Audio Instructions Source: https://laravel.com/docs/master/ai-sdk Provide dynamic coaching to influence the style of generated audio. ```php $audio = Audio::of('I love coding with Laravel.') ->female() ->instructions('Said like a pirate') ->generate(); ``` -------------------------------- ### Manage ChromeDriver Installation Source: https://laravel.com/docs/master/dusk Use the dusk:chrome-driver command to install specific versions of ChromeDriver. You can install the latest version, a specific version, or for all supported operating systems. ```shell php artisan dusk:chrome-driver ``` ```shell php artisan dusk:chrome-driver 86 ``` ```shell php artisan dusk:chrome-driver --all ``` -------------------------------- ### Install Tinker Source: https://laravel.com/docs/master/artisan Installs the Laravel Tinker package via Composer. ```shell composer require laravel/tinker ``` -------------------------------- ### Get Storage Directory Path Source: https://laravel.com/docs/master/helpers Use `storage_path()` to get the path to the application's storage directory. Provide a relative path to get a file within the storage directory. ```php $path = storage_path(); ``` ```php $path = storage_path('app/file.txt'); ``` -------------------------------- ### Initialize Octane Configuration Source: https://laravel.com/docs/master/octane Run the Artisan command to publish the Octane configuration file. ```shell php artisan octane:install ``` -------------------------------- ### Finalize RoadRunner Sail Setup Source: https://laravel.com/docs/master/octane Make the binary executable and rebuild the Sail images. ```shell chmod +x ./rr ./vendor/bin/sail build --no-cache ``` -------------------------------- ### Get Resources Directory Path Source: https://laravel.com/docs/master/helpers Use `resource_path()` to get the path to the application's resources directory. Provide a relative path to get a file within the resources directory. ```php $path = resource_path(); ``` ```php $path = resource_path('sass/app.scss'); ``` -------------------------------- ### Get Public Directory Path Source: https://laravel.com/docs/master/helpers Use `public_path()` to get the path to the application's public directory. Provide a relative path to get a file within the public directory. ```php $path = public_path(); ``` ```php $path = public_path('css/app.css'); ``` -------------------------------- ### Vue Project Directory Structure Source: https://laravel.com/docs/master/starter-kits Overview of the primary frontend directory structure for Vue starter kits. ```text resources/js/ ├── components/ # Reusable Vue components ├── composables/ # Vue composables / hooks ├── layouts/ # Application layouts ├── lib/ # Utility functions and configuration ├── pages/ # Page components └── types/ # TypeScript definitions ``` -------------------------------- ### Get Language Directory Path Source: https://laravel.com/docs/master/helpers Use `lang_path()` to get the path to the application's language directory. Provide a relative path to get a file within the language directory. ```php $path = lang_path(); ``` ```php $path = lang_path('en/messages.php'); ``` -------------------------------- ### Start Reverb Server with Host and Port Source: https://laravel.com/docs/master/reverb Start the Reverb server, specifying the host and port. This command is useful for local development, especially when integrating with tools like Laravel Herd or Valet for SSL. ```shell php artisan reverb:start --host="0.0.0.0" --port=8080 --hostname="laravel.test" ``` -------------------------------- ### Get Database Directory Path Source: https://laravel.com/docs/master/helpers Use `database_path()` to get the path to the application's database directory. Provide a relative path to get a file within the database directory. ```php $path = database_path(); ``` ```php $path = database_path('factories/UserFactory.php'); ``` -------------------------------- ### Get Configuration Directory Path Source: https://laravel.com/docs/master/helpers Use `config_path()` to get the path to the application's configuration directory. Provide a relative path to get a file within the config directory. ```php $path = config_path(); ``` ```php $path = config_path('app.php'); ``` -------------------------------- ### Generate project configuration files Source: https://laravel.com/docs/master/homestead Create the Vagrantfile and Homestead.yaml in the project root. ```shell # macOS / Linux... php vendor/bin/homestead make # Windows... vendor\bin\homestead make ``` -------------------------------- ### Get Project Root Directory Path Source: https://laravel.com/docs/master/helpers Use `base_path()` to get the path to the project's root directory. Provide a relative path to get a file within the project root. ```php $path = base_path(); ``` ```php $path = base_path('vendor/bin'); ``` -------------------------------- ### Install ext-uv PECL Package Source: https://laravel.com/docs/master/reverb Install the `ext-uv` PHP extension via PECL to enable a more performant event loop for handling a large number of concurrent connections. ```shell pecl install uv ``` -------------------------------- ### Install Laravel Scout Source: https://laravel.com/docs/master/scout Install Scout using the Composer package manager. ```shell composer require laravel/scout ``` -------------------------------- ### Initiate Guest Checkout Session Source: https://laravel.com/docs/master/billing Use `Checkout::guest()->create()` to start a checkout session for a guest user. Ensure your success and cancel URLs are correctly defined. ```php use Illuminate\Http\Request; use Laravel\Cashier\Checkout; Route::get('/product-checkout', function (Request $request) { return Checkout::guest()->create('price_tshirt', [ 'success_url' => route('your-success-route'), 'cancel_url' => route('your-cancel-route'), ]); }); ``` -------------------------------- ### Install @laravel/stream-vue Source: https://laravel.com/docs/master/responses Install the Vue package for consuming Laravel event streams. ```shell npm install @laravel/stream-vue ``` -------------------------------- ### Install Laravel MCP Source: https://laravel.com/docs/master/mcp Install the Laravel MCP package using Composer. ```shell composer require laravel/mcp ``` -------------------------------- ### Install Swoole Extension Source: https://laravel.com/docs/master/octane Install the Swoole PHP extension using PECL. ```shell pecl install swoole ``` -------------------------------- ### Configure Read and Write Database Connections Source: https://laravel.com/docs/master/database Example configuration array for splitting read and write database traffic, including the sticky option. ```php 'mysql' => [ 'driver' => 'mysql', 'read' => [ 'host' => [ '192.168.1.1', '196.168.1.2', ], ], 'write' => [ 'host' => [ '192.168.1.3', ], ], 'sticky' => true, 'port' => env('DB_PORT', '3306'), 'database' => env('DB_DATABASE', 'laravel'), 'username' => env('DB_USERNAME', 'root'), 'password' => env('DB_PASSWORD', ''), 'unix_socket' => env('DB_SOCKET', ''), 'charset' => env('DB_CHARSET', 'utf8mb4'), 'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'), 'prefix' => '', 'prefix_indexes' => true, 'strict' => true, 'engine' => null, 'options' => extension_loaded('pdo_mysql') ? array_filter([ (PHP_VERSION_ID >= 80500 ? \Pdo\Mysql::ATTR_SSL_CA : \PDO::MYSQL_ATTR_SSL_CA) => env('MYSQL_ATTR_SSL_CA'), ]) : [], ], ``` -------------------------------- ### Install Laravel Pint Source: https://laravel.com/docs/master/pint Install the package as a development dependency via Composer. ```shell composer require laravel/pint --dev ``` -------------------------------- ### Start Supervisor Processes Source: https://laravel.com/docs/master/queues Commands to refresh and start Supervisor worker processes. ```shell sudo supervisorctl reread sudo supervisorctl update sudo supervisorctl start "laravel-worker:*" ``` -------------------------------- ### Execute a basic request in tests Source: https://laravel.com/docs/master/http-tests Shows the standard way to initiate a request and inspect the returned TestResponse instance. ```php get('/'); $response->assertStatus(200); }); ``` ```php get('/'); $response->assertStatus(200); } } ``` -------------------------------- ### Install Laravel Sanctum Source: https://laravel.com/docs/master/sanctum Use the Artisan command to install Sanctum into your Laravel application. ```shell php artisan install:api ``` -------------------------------- ### Install Dropbox Adapter Source: https://laravel.com/docs/master/filesystem Use Composer to add the community-maintained Dropbox adapter to the project. ```shell composer require spatie/flysystem-dropbox ``` -------------------------------- ### Start a queue worker with verbose output Source: https://laravel.com/docs/master/queues Includes job IDs, connection names, and queue names in the command output. ```shell php artisan queue:work -v ``` -------------------------------- ### Start a queue worker Source: https://laravel.com/docs/master/queues Starts a queue worker that processes jobs until manually stopped. ```shell php artisan queue:work ``` -------------------------------- ### Accessing Laravel Facades Source: https://laravel.com/docs/master/facades Demonstrates importing and using facades to interact with framework features like Cache and Route. ```php use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Route; Route::get('/cache', function () { return Cache::get('key'); }); ``` -------------------------------- ### Anonymous Event JSON Example Source: https://laravel.com/docs/master/broadcasting Example of a JSON payload broadcasted for an anonymous event. ```json { "event": "AnonymousEvent", "data": "[]", "channel": "orders.1" } ``` -------------------------------- ### Lazy Loading Example (N+1 Problem) Source: https://laravel.com/docs/master/eloquent-relationships Illustrates the N+1 query problem by retrieving all books and then accessing the author's name in a loop, resulting in multiple queries. ```php use App\Models\Book; $books = Book::all(); foreach ($books as $book) { echo $book->author->name; } ``` -------------------------------- ### Install SRI Plugin Source: https://laravel.com/docs/master/vite Install the vite-plugin-manifest-sri package to enable Subresource Integrity hashes in the manifest. ```shell npm install --save-dev vite-plugin-manifest-sri ``` -------------------------------- ### Example Custom Skill File Path Source: https://laravel.com/docs/master/boost Create custom skills by placing a SKILL.md file in the specified directory structure. This allows for tailored AI assistance for your application's domain logic. ```bash .ai/skills/creating-invoices/SKILL.md ``` -------------------------------- ### Install Additional Symfony Transports Source: https://laravel.com/docs/master/mail Use Composer to install the required Symfony mailer packages. ```shell composer require symfony/brevo-mailer symfony/http-client ``` -------------------------------- ### Show Configuration File Values Source: https://laravel.com/docs/master/configuration Inspect the detailed values of a specific configuration file using the config:show command. ```shell php artisan config:show database ``` -------------------------------- ### Create User with Generic Trial Source: https://laravel.com/docs/master/cashier-paddle Create a new user and immediately assign them a trial period without requiring payment information upfront. The trial duration is set using `now()->plus(days: 10)`. ```php use App\Models\User; $user = User::create([ // ... ]); $user->createAsCustomer([ 'trial_ends_at' => now()->plus(days: 10) ]); ``` -------------------------------- ### Execute closure when string starts with substring Source: https://laravel.com/docs/master/strings Invokes the closure if the string starts with the specified substring. ```php use Illuminate\Support\Str; use Illuminate\Support\Stringable; $string = Str::of('disney world')->whenStartsWith('disney', function (Stringable $string) { return $string->title(); }); // 'Disney World' ``` -------------------------------- ### Execute closure when string does not start with substring Source: https://laravel.com/docs/master/strings Invokes the closure if the string does not start with the specified substring. ```php use Illuminate\Support\Str; use Illuminate\Support\Stringable; $string = Str::of('disney world')->whenDoesntStartWith('sea', function (Stringable $string) { return $string->title(); }); // 'Disney World' ``` -------------------------------- ### Initialize Homestead Configuration Source: https://laravel.com/docs/master/homestead Run the init script to create the 'Homestead.yaml' configuration file. This file is essential for customizing your Homestead environment. ```shell # macOS / Linux... bash init.sh # Windows... init.bat ``` -------------------------------- ### Str::start Source: https://laravel.com/docs/master/strings Adds a single instance of a value to the start of a string if it does not already start with that value. ```APIDOC ## Str::start ### Description The Str::start method adds a single instance of the given value to a string if it does not already start with that value. ``` -------------------------------- ### Create Subscription After Generic Trial Source: https://laravel.com/docs/master/billing Initialize a standard subscription for a user who was previously on a generic trial. ```php $user = User::find(1); $user->newSubscription('default', 'price_monthly')->create($paymentMethod); ``` -------------------------------- ### Implement Basic Web Fetch Provider Tool Source: https://laravel.com/docs/master/ai-sdk The `WebFetch` provider tool allows agents to fetch and read the contents of web pages. It can be included in the agent's `tools` method. ```php use Laravel\Ai\Providers\Tools\WebFetch; public function tools(): iterable { return [ new WebFetch, ]; } ``` -------------------------------- ### Install Svelte Plugin for Vite Source: https://laravel.com/docs/master/vite Install the @sveltejs/vite-plugin-svelte package as a development dependency if you are using Svelte with Vite. ```shell npm install --save-dev @sveltejs/vite-plugin-svelte ``` -------------------------------- ### Install React Plugin for Vite Source: https://laravel.com/docs/master/vite Install the @vitejs/plugin-react package as a development dependency if you are using React with Vite. ```shell npm install --save-dev @vitejs/plugin-react ``` -------------------------------- ### Configure Pint via JSON Source: https://laravel.com/docs/master/pint Define configuration settings in a pint.json file. ```json { "preset": "laravel" } ``` ```json { "preset": "psr12" } ``` -------------------------------- ### Install Vue Plugin for Vite Source: https://laravel.com/docs/master/vite Install the @vitejs/plugin-vue package as a development dependency if you are using Vue with Vite. ```shell npm install --save-dev @vitejs/plugin-vue ``` -------------------------------- ### Install Algolia SDK Source: https://laravel.com/docs/master/scout Install the Algolia PHP SDK via Composer when using the Algolia driver. ```shell composer require algolia/algoliasearch-client-php ``` -------------------------------- ### Update Laravel Installer via Composer Source: https://laravel.com/docs/master/upgrade Use this command to update the global Laravel installer package. ```shell composer global update laravel/installer ``` -------------------------------- ### Handling Real-time Process Output Source: https://laravel.com/docs/master/processes Pass a closure to the start method to receive output as it is generated by the process. ```php $process = Process::start('bash import.sh', function (string $type, string $output) { echo $output; }); $result = $process->wait(); ``` -------------------------------- ### Install Vonage Notification Dependencies Source: https://laravel.com/docs/master/notifications Install the required packages for Vonage SMS notifications via Composer. ```shell composer require laravel/vonage-notification-channel guzzlehttp/guzzle ```