### Install Menu Component Source: https://github.com/laravel-zero/docs/blob/master/build-interactive-menus.md Install the menu component using the app:install Artisan command. This component requires the ext-posix PHP extension and will not work on Windows. ```bash php app:install menu ``` -------------------------------- ### Install Logging Component Source: https://github.com/laravel-zero/docs/blob/master/logging.md Use the app:install command to add the log component to your application. ```bash php app:install log ``` -------------------------------- ### Install Redis Component Source: https://github.com/laravel-zero/docs/blob/master/database.md Install the Redis component using the app:install Artisan command. This allows for the use of Redis for fast data storage and caching. ```bash php app:install redis ``` -------------------------------- ### Install HTTP Client Component Source: https://github.com/laravel-zero/docs/blob/master/http-client.md Run this command to install the HTTP client component into your Laravel Zero application. ```shell php app:install http ``` -------------------------------- ### Example Inspiring Command in Laravel Zero Source: https://github.com/laravel-zero/docs/blob/master/commands.md This is an example of a basic Artisan command, including its signature, description, and handle method. It demonstrates how to display information to the console. ```php namespace App\Commands; use Illuminate\Console\Scheduling\Schedule; use LaravelZero\Framework\Commands\Command; class InspiringCommand extends Command { /** * The signature of the command. * * @var string */ protected $signature = 'inspiring {name=Artisan}'; /** * The description of the command. * * @var string */ protected $description = 'Display an inspiring quote'; /** * Execute the console command. */ public function handle(): void { $this->info('Simplicity is the ultimate sophistication.'); } /** * Define the command's schedule. */ public function schedule(Schedule $schedule): void { // $schedule->command(static::class)->everyMinute(); } } ``` -------------------------------- ### Install View Component Source: https://github.com/laravel-zero/docs/blob/master/view.md Install the View component using the Artisan command. This command adds the necessary files and configurations for view support. ```bash php app:install view ``` -------------------------------- ### Install Console Dusk Component Source: https://github.com/laravel-zero/docs/blob/master/web-browser-automation.md Use the `app:install` Artisan command to add the `console-dusk` component to your Laravel Zero application. ```bash php app:install console-dusk ``` -------------------------------- ### Install Database Component Source: https://github.com/laravel-zero/docs/blob/master/database.md Install the database component using the app:install Artisan command. This enables Laravel's Eloquent ORM and related features. ```bash php app:install database ``` -------------------------------- ### Insert and Get Data with Eloquent Source: https://github.com/laravel-zero/docs/blob/master/database.md Use the DB facade to insert a new record into the 'users' table and retrieve all records from the 'users' table. Ensure the database component is installed. ```php use Illuminate\Support\Facades\DB; DB::table('users')->insert( ['email' => 'enunomaduro@gmail.com'] ); $users = DB::table('users')->get(); ``` -------------------------------- ### Laravel Zero Test Case Setup Source: https://github.com/laravel-zero/docs/blob/master/upgrade.md The TestCase.php file should be configured as shown to set up your testing environment. ```php app:install dotenv ``` -------------------------------- ### Write an Integration Test with Pest Source: https://github.com/laravel-zero/docs/blob/master/testing.md Example of an integration test using Pest syntax. This test verifies the 'inspiring' Artisan command. ```php test('inspiring command', function () { $this->artisan('inspiring') ->expectsOutput('Simplicity is the ultimate sophistication.') ->assertExitCode(0); }); ``` -------------------------------- ### Visit Website and Assert Content Source: https://github.com/laravel-zero/docs/blob/master/web-browser-automation.md This command demonstrates how to use Laravel Dusk within an Artisan command to visit a URL and assert that specific text is present on the page. Ensure the `console-dusk` component is installed. ```php class VisitLaravelZeroCommand extends Command { public function handle(): void { $this->browse(function ($browser) { $browser->visit('https://laravel-zero.com') ->assertSee('Laravel Zero'); }); } } ``` -------------------------------- ### Define Command Signature with Arguments and Options Source: https://github.com/laravel-zero/docs/blob/master/commands.md The `signature` property defines how your command accepts input. This example shows how to define a required argument for the user's name and an optional argument for their age. ```php protected $signature = 'user:create {name : The name of the user (required)} {--age= : The age of the user (optional)}' ``` -------------------------------- ### Install Self-Update Component Source: https://github.com/laravel-zero/docs/blob/master/distribute-as-a-phar-archive.md Use the app:install Artisan command to add the self-update component to your built application. This component provides an Artisan command to automatically update the application from GitHub. ```bash php app:install self-update ``` -------------------------------- ### Set and Get Data with Redis Source: https://github.com/laravel-zero/docs/blob/master/database.md Utilize the Redis facade to set a key-value pair and retrieve the value associated with a key. Ensure Redis is configured in config/database.php. ```php use Illuminate\Support\Facades\Redis; Redis::set('full_name', 'Daniel LaRusso'); Redis::get('full_name'); ``` -------------------------------- ### Log Messages with Laravel Facade Source: https://github.com/laravel-zero/docs/blob/master/logging.md Utilize the Log facade to send messages at different severity levels. Ensure the 'log' component is installed. ```php use Illuminate\Support\Facades\Log; Log::emergency($message); Log::alert($message); Log::critical($message); Log::error($message); Log::warning($message); Log::notice($message); Log::info($message); Log::debug($message); ``` -------------------------------- ### Define Scheduled Tasks Source: https://github.com/laravel-zero/docs/blob/master/task-scheduling.md Define all your scheduled tasks within the `schedule` method of your Artisan command. This example schedules a command to run every minute. ```php public function schedule(Schedule $schedule): void { $schedule->command(static::class)->everyMinute(); } ``` -------------------------------- ### Send a Desktop Notification Source: https://github.com/laravel-zero/docs/blob/master/send-desktop-notifications.md Use the `notify` method within your Artisan commands to display a desktop notification. Requires the `laravel-desktop-notifier` package. On macOS, `terminal-notifier` must be installed for icons to display. ```php $this->notify("Hello Web Artisan", "Love beautiful..", "icon.png"); ``` -------------------------------- ### Composer Global Require for Packagist Source: https://github.com/laravel-zero/docs/blob/master/distribute-as-a-phar-archive.md After building your application and configuring it for Packagist distribution, users can install your application globally using the composer global require command. ```bash composer global require ``` -------------------------------- ### Configure Compiled Views Path Source: https://github.com/laravel-zero/docs/blob/master/view.md In production, configure the path for compiled Blade views by creating a `view.php` file in the `config` directory. This example shows how to set the paths and compiled view location. ```php [ resource_path('views'), ], 'compiled' => \Phar::running() ? getcwd() : env('VIEW_COMPILED_PATH', realpath(storage_path('framework/views'))), ]; ``` -------------------------------- ### Project Structure with .env File Source: https://github.com/laravel-zero/docs/blob/master/environment-variables.md After building your application, place the .env file in the root directory alongside the 'application' folder to ensure environment variables are loaded correctly. ```text .\n├── .env\n└── application ``` -------------------------------- ### Run executable binary on Windows Source: https://github.com/laravel-zero/docs/blob/master/distribute-as-a-single-executable-binary.md Execute the built binary directly on Windows. The path specifies the architecture (x64) and includes the .exe extension. ```bash C:\application\path> builds\build\windows\windows-x64.exe ``` -------------------------------- ### Command Logic Implementation Source: https://github.com/laravel-zero/docs/blob/master/commands.md The `handle` method contains the core logic of your command. Dependencies can be injected directly into this method. Use `$this->info()` to display output. ```php public function handle(Service $service): void { $service->execute('foo'); $this->info('Operation executed'); } ``` -------------------------------- ### Registering a Singleton Service Provider Source: https://github.com/laravel-zero/docs/blob/master/service-providers.md Use the `register` method to bind an interface to a concrete implementation using `app->singleton`. This allows for dependency injection of the contract. ```php public function register() { $this->app->singleton(Contract::class, function ($app) { return new Concrete(config('database')); }); } app(Contract::class) // Returns a Concrete implementation. ``` -------------------------------- ### Application Entry Point Source: https://github.com/laravel-zero/docs/blob/master/upgrade.md This is the main entry point for interacting with your Laravel Zero application. It should contain the provided content to ensure proper application bootstrapping and execution. ```php make( Illuminate\Contracts\Console\Kernel::class ); $kernel->bootstrap(); exit($kernel->handle( $app['request'] )->toResponse($app['request'])->send()); ``` -------------------------------- ### Run executable binary on Linux Source: https://github.com/laravel-zero/docs/blob/master/distribute-as-a-single-executable-binary.md Execute the built binary directly on Linux. The path specifies the architecture (x64). ```bash ./builds/build/linux/linux-x64 ``` -------------------------------- ### Create a Basic Interactive Menu Source: https://github.com/laravel-zero/docs/blob/master/build-interactive-menus.md Create a simple interactive menu in your command's handle function. The menu method returns the selected option number. ```php $option = $this->menu('Pizza menu', [ 'Freshly baked muffins', 'Freshly baked croissants', 'Turnovers, crumb cake, cinnamon buns, scones', ])->open(); $this->info("You have chosen the option number #$option"); ``` -------------------------------- ### Configuration for Commands Source: https://github.com/laravel-zero/docs/blob/master/upgrade.md This configuration file defines the commands that should appear in your application's ListCommand. Customize it to specify which commands are relevant. ```php App\Commands\Inspire::class, /* |-------------------------------------------------------------------------- | Commands Paths |-------------------------------------------------------------------------- | | Here you may specify the paths to the commands that should be loaded. | */ 'paths' => [ app_path('Commands'), ], /* |-------------------------------------------------------------------------- | Commands |-------------------------------------------------------------------------- | | This is the array of commands that will be available in your application. | */ 'commands' => [ // App\Command\ExampleCommand::class, ], ]; ``` -------------------------------- ### Build PHAR archive Source: https://github.com/laravel-zero/docs/blob/master/distribute-as-a-single-executable-binary.md Build your PHAR archive with the .phar extension before creating the binary. This command assumes 'app:build' is a custom command in your Laravel Zero project. ```bash php app:build .phar ``` -------------------------------- ### Build executable binaries with PHPacker Source: https://github.com/laravel-zero/docs/blob/master/distribute-as-a-single-executable-binary.md Create binaries for all supported platforms using PHPacker, embedding PHP 8.4. The --src flag points to the PHAR archive, and 'all' specifies all supported platforms. ```bash ./vendor/bin/phpacker build --src=./builds/.phar --php=8.4 all ``` -------------------------------- ### Laravel Zero Application Creation Trait Source: https://github.com/laravel-zero/docs/blob/master/upgrade.md The CreatesApplication.php file contains the trait responsible for bootstrapping the application for testing. ```php make( Illuminate\Contracts\Console\Kernel::class )->bootstrap(); return $app; } } ``` -------------------------------- ### Write file using File facade Source: https://github.com/laravel-zero/docs/blob/master/filesystem.md Use this to write content to a file using the File facade. Specify the absolute path to the file. ```php use Illuminate\Support\Facades\File; File::put("/path/to/file/reminders.txt", "Task 1"); ``` -------------------------------- ### Write file in production using File facade Source: https://github.com/laravel-zero/docs/blob/master/filesystem.md When running a built application, use this method to write files to the current working directory using the File facade. ```php File::put(getcwd() . "/reminders.txt", "Task 1"); ``` -------------------------------- ### Using Artisan Facade in Tests Source: https://github.com/laravel-zero/docs/blob/master/upgrade.md When writing tests, replace calls to `$this->app->call()` and `$this->app->output()` with the Artisan facade for consistency. ```php Artisan::call('command:name'); Artisan::output(); ``` -------------------------------- ### Run executable binary on macOS Source: https://github.com/laravel-zero/docs/blob/master/distribute-as-a-single-executable-binary.md Execute the built binary directly on macOS. The path specifies the architecture (arm or x64). ```bash ./builds/build/mac/mac-arm ``` -------------------------------- ### View Scheduled Tasks Source: https://github.com/laravel-zero/docs/blob/master/task-scheduling.md Use the `schedule:list` command to view a list of all tasks scheduled in your application. Replace `` with your actual application name. ```shell php schedule:list ``` -------------------------------- ### Publish Cache Configuration Source: https://github.com/laravel-zero/docs/blob/master/cache.md Use this command to publish the cache configuration file to your application. This allows you to define custom cache drivers. ```bash php config:publish cache ``` -------------------------------- ### Execute PHAR Archive Source: https://github.com/laravel-zero/docs/blob/master/distribute-as-a-phar-archive.md After building, you can execute the PHAR archive directly. The execution method varies slightly between Unix-like systems and Windows. ```bash ./builds/ ``` ```bash C:\application\path> php builds\ ``` -------------------------------- ### Write file using Storage facade Source: https://github.com/laravel-zero/docs/blob/master/filesystem.md Use this to write content to a file using the Storage facade. By default, files are stored in the `your-app-name/storage` directory. ```php use Illuminate\Support\Facades\Storage; Storage::put("reminders.txt", "Task 1"); ``` -------------------------------- ### Box Configuration for Application Bundling Source: https://github.com/laravel-zero/docs/blob/master/upgrade.md This JSON configuration file is used by humbug/box for fast application bundling. It specifies directories, files, and compression settings. ```json { "chmod": "0755", "directories": [ "app", "bootstrap", "config", "vendor" ], "files": [ "composer.json" ], "exclude-composer-files": false, "compression": "GZ", "compactors": [ "Herrera\\Box\\Compactor\\Php", "Herrera\\Box\\Compactor\\Json" ] } ``` -------------------------------- ### Create a New Artisan Command Source: https://github.com/laravel-zero/docs/blob/master/commands.md Use this Artisan command to generate a new command file within your application. Replace `` with your application's name and `` with your desired command name. ```bash php make:command ``` -------------------------------- ### Create Application Trait for Testing Source: https://github.com/laravel-zero/docs/blob/master/upgrade.md This trait is used in testing to create the application instance. It requires the Illuminate Contracts Console Kernel. ```php make(Kernel::class)->bootstrap(); return $app; } } ``` -------------------------------- ### Build PHAR Archive Source: https://github.com/laravel-zero/docs/blob/master/distribute-as-a-phar-archive.md Use this command to build a standalone PHAR archive of your Laravel Zero project. The build process uses humbug/box for bundling. ```bash php app:build ``` -------------------------------- ### Configure local disk to use current working directory Source: https://github.com/laravel-zero/docs/blob/master/filesystem.md This configuration replaces the default storage directory with the current working directory when running a built application. Place this in `config/filesystems.php`. ```php 'local', 'disks' => [ 'local' => [ 'driver' => 'local', 'root' => getcwd(), ], ], ]; ``` -------------------------------- ### Bootstrap Cache .gitignore Source: https://github.com/laravel-zero/docs/blob/master/upgrade.md This .gitignore file ensures that only the .gitignore file itself is committed to the bootstrap/cache directory, while other generated files are ignored. ```gitignore * !.gitignore ``` -------------------------------- ### Rename Laravel Zero Project Source: https://github.com/laravel-zero/docs/blob/master/installation.md After creating the project, run this command to rename your application. Replace `movie-cli` with your desired project name. ```bash php application app:rename [movie-cli] ``` -------------------------------- ### Cron Entry for Task Scheduling Source: https://github.com/laravel-zero/docs/blob/master/task-scheduling.md Add this cron entry to your server to periodically execute the scheduler. Ensure the path to your application and the application name are correct. ```shell * * * * * php /path-to-your-project/your-app-name schedule:run >> /dev/null 2>&1 ``` -------------------------------- ### Update App Configuration for Environment Source: https://github.com/laravel-zero/docs/blob/master/upgrade.md The `app.production` configuration value has been removed and replaced by `app.env` to match Laravel. Update your `config/app.php` accordingly. ```php 'env' => 'development' ``` -------------------------------- ### Run Pest Tests Source: https://github.com/laravel-zero/docs/blob/master/testing.md Command to execute all tests in your Laravel Zero project using the Pest test runner. ```bash ./vendor/bin/pest ``` -------------------------------- ### Render HTML Views with Blade Source: https://github.com/laravel-zero/docs/blob/master/view.md Use the View facade or the global `view` helper function to render Blade views. Pass data as an associative array to the view. ```php use Illuminate\Support\Facades\View; View::make('view.name', ['foo' => 'bar']); view('view-name', ['foo' => 'bar']); ``` -------------------------------- ### Publish Updater Configuration Source: https://github.com/laravel-zero/docs/blob/master/distribute-as-a-phar-archive.md To customize the self-update strategy, first publish the configuration file for the updater component using the vendor:publish Artisan command. ```bash php vendor:publish --provider "LaravelZero\Framework\Components\Updater\Provider" ``` -------------------------------- ### Include Resources Directory in PHAR Source: https://github.com/laravel-zero/docs/blob/master/view.md Ensure the `resources` directory is included in the compiled PHAR file by adding it to the `directories` array in your `box.json` configuration. ```json "directories": [ // ... "resources" ], ``` -------------------------------- ### Non-interactive PHAR Build Source: https://github.com/laravel-zero/docs/blob/master/distribute-as-a-phar-archive.md Skip the interactive prompt for build version during PHAR creation by providing the build version directly as an option. ```bash php your-app-name app:build --build-version= ``` -------------------------------- ### Return task results Source: https://github.com/laravel-zero/docs/blob/master/run-tasks.md Use the `task` method to define a task and return a boolean indicating success or failure. This provides visual feedback to the end-user. ```php $this->task("Installing Laravel", function () { return true; }); $this->task("Doing something else", function () { return false; }); ``` -------------------------------- ### Configure Box for Packagist Distribution Source: https://github.com/laravel-zero/docs/blob/master/distribute-as-a-phar-archive.md To ensure development dependencies are not included in the PHAR when distributing via Packagist, set 'exclude-dev-files' to false in your box.json configuration. ```json "exclude-dev-files": false, ``` -------------------------------- ### Configure Log Path for PHAR Builds Source: https://github.com/laravel-zero/docs/blob/master/logging.md When your application is built as a PHAR, the default storage path for logs is read-only. Reconfigure the log path in the AppServiceProvider to ensure logs are written to a writable location. ```php public function boot() { # ensure you configure the right channel you use config(['logging.channels.single.path' => \Phar::running() ? dirname(\Phar::running(false)) . '/desired-path/your-app.log' : storage_path('logs/your-app.log') ]); } ``` -------------------------------- ### Configure Composer for Packagist Distribution Source: https://github.com/laravel-zero/docs/blob/master/distribute-as-a-phar-archive.md When distributing via Packagist, move framework and custom dependencies to 'require-dev' and update the 'bin' path in composer.json to point to your PHAR build. ```diff "require": [ "laravel-zero/framework": "x.x" ] "bin": [""] ``` ```diff "require-dev": [ "laravel-zero/framework": "x.x" ] "bin": ["builds/"] ``` -------------------------------- ### Base Test Case for Laravel Zero Source: https://github.com/laravel-zero/docs/blob/master/upgrade.md Extends the base Laravel Zero test case and uses the CreatesApplication trait for testing. ```php [ 'sqlite' => [ 'driver' => 'sqlite', 'url' => env('DATABASE_URL'), - 'database' => database_path('database.sqlite'), + 'database' => $_SERVER['HOME'] . '/.your-project-name/database.sqlite', 'prefix' => '', 'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true), ], ] ``` -------------------------------- ### Update PHPUnit Configuration Source: https://github.com/laravel-zero/docs/blob/master/upgrade.md Remove the `NunoMaduro\Collision\Adapters\Phpunit\Listener` class from your `listeners` block in `phpunit.xml.dist` when upgrading to PHPUnit 9.3. ```xml ``` -------------------------------- ### Using a Service Contract in a Handler Source: https://github.com/laravel-zero/docs/blob/master/service-providers.md Inject the service contract directly into methods, such as in a handler, to utilize its functionality without needing to know the concrete implementation. ```php public function handle(ServiceContract $service): void { $service->execute('foo'); } ``` -------------------------------- ### Debug PHAR Build Failures Source: https://github.com/laravel-zero/docs/blob/master/distribute-as-a-phar-archive.md If your PHAR build fails, use the verbose flag (-v) with the build command or the box compile command with debug flags for more detailed output. This can help identify issues like missing PHP extensions. ```shell # -v for Verbose php app:build -v ``` ```shell # This does the compiling, so can be used if -v isn't helping you. ./vendor/laravel-zero/framework/bin/box compile --working-dir=/project/path --config=/project/path/box.json --debug ``` -------------------------------- ### Customize Menu Appearance Source: https://github.com/laravel-zero/docs/blob/master/build-interactive-menus.md Customize the appearance of the interactive menu using a fluent API. Options include setting colors, width, padding, margin, exit button text, title separator, and adding line breaks or static items. ```php $this->menu($title, $options) ->setForegroundColour('green') ->setBackgroundColour('black') ->setWidth(200) ->setPadding(10) ->setMargin(5) ->setExitButtonText("Abort") // remove exit button with // ->disableDefaultItems() ->setTitleSeparator('*-') ->addLineBreak('<3', 2) ->addStaticItem('AREA 2') ->open(); ``` -------------------------------- ### Access Environment Variables Source: https://github.com/laravel-zero/docs/blob/master/environment-variables.md After setting environment variables in your .env file, you can access their values using the env() helper function in your PHP code. Ensure the .env file is correctly named and placed. ```php echo env('SECRET_KEY') // outputs 234567 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.