### Laravel DB Facade - Basic SELECT Example Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/database.md A PHP example demonstrating how to fetch user data using the DB::select method with a placeholder. ```php $users]); } } ``` -------------------------------- ### Example Database Connection URL Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/database.md An example of a MySQL database connection URL, demonstrating the format used by Laravel for simplified database configuration. ```html mysql://root:password@127.0.0.1/forge?charset=UTF-8 ``` -------------------------------- ### Basic Breeze Installation Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/starter-kits.md Installs Laravel Breeze with default settings, runs database migrations, installs npm dependencies, and starts the development server. ```shell php artisan breeze:install react php artisan migrate npm install npm run dev ``` -------------------------------- ### Start Laravel Development Server Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/installation.md Navigates into the project directory and starts Laravel's local development server using the Artisan CLI. The application will be accessible at http://localhost:8000. ```shell cd example-app php artisan serve ``` -------------------------------- ### Laravel Database Configuration (Read/Write) Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/database.md Example configuration for a MySQL database connection in Laravel, demonstrating separate read and write hosts, and the 'sticky' option. ```php 'mysql' => [ 'read' => [ 'host' => [ '192.168.1.1', '196.168.1.2', ], ], 'write' => [ 'host' => [ '196.168.1.3', ], ], 'sticky' => true, 'driver' => 'mysql', 'database' => 'database', 'username' => 'root', 'password' => '', 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', ] ``` -------------------------------- ### Start Laravel Sail (Docker) Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/installation.md Navigates into the project directory created with Docker and starts the Laravel Sail development environment. The application will be accessible at http://localhost. ```shell cd example-app ./vendor/bin/sail up ``` -------------------------------- ### Building Eloquent Queries Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Constructs database queries using Eloquent's fluent interface. Constraints like `where`, `orderBy`, and `take` can be chained before executing the query with `get`. ```php $flights = Flight::where('active', 1) ->orderBy('name') ->take(10) ->get(); ``` -------------------------------- ### Start Laravel Sail Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/installation.md After navigating to the application directory, this command starts the Docker containers for your Laravel project using Laravel Sail. Sail provides a command-line interface for interacting with Laravel's default Docker configuration. ```bash cd example-app ./vendor/bin/sail up ``` -------------------------------- ### Registering Eloquent Model Event Listeners with Closures Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md This example shows how to register model event listeners using closures within the `booted` method of an Eloquent model. It illustrates listening for the 'created' event and executing a closure when it occurs. ```php assertEquals(4, $result); } } ``` -------------------------------- ### User Observer Class Example Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md A basic structure for a UserObserver class in Laravel, demonstrating methods for handling Eloquent events like 'created', 'updated', 'deleted', 'restored', and 'forceDeleted'. Each method receives the affected User model as an argument. ```php 1]) - Executes a SELECT query using named bindings. - Parameters: - query: The SQL query string with named placeholders (e.g., :id). - bindings: An associative array mapping placeholder names to their values. - Returns: An array of stdClass objects. - Example: $results = DB::select('select * from users where id = :id', ['id' => 1]); DB::insert(query, bindings) - Executes an INSERT SQL query. - Parameters: - query: The SQL query string. - bindings: An array of parameters to bind to the query. - Returns: Boolean indicating success or failure. DB::update(query, bindings) - Executes an UPDATE SQL query. - Parameters: - query: The SQL query string. - bindings: An array of parameters to bind to the query. - Returns: The number of affected rows. DB::delete(query, bindings) - Executes a DELETE SQL query. - Parameters: - query: The SQL query string. - bindings: An array of parameters to bind to the query. - Returns: The number of affected rows. DB::statement(query, bindings) - Executes a general SQL statement (e.g., DDL statements). - Parameters: - query: The SQL statement string. - bindings: An array of parameters to bind to the statement. - Returns: Boolean indicating success or failure. ``` -------------------------------- ### Filesystem Configuration for Flysystem 3.x Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/upgrade.md Provides an example of configuring the Filesystem disk to preserve the previous exception-throwing behavior for write operations in Flysystem 3.x. ```PHP 'public' => [ 'driver' => 'local', // ... 'throw' => true, ], ``` -------------------------------- ### GitHub Actions Configuration for Dusk Tests Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/dusk.md This snippet provides a starting point for a GitHub Actions workflow to run Laravel Dusk tests. It covers checking out code, preparing the environment, setting up a database, installing Composer dependencies, generating keys, updating the Chrome driver, starting Chrome and the Laravel server, and running Dusk tests. It also includes steps for uploading artifacts on failure. ```yaml name: CI on: [push] jobs: dusk-php: runs-on: ubuntu-latest env: APP_URL: "http://127.0.0.1:8000" DB_USERNAME: root DB_PASSWORD: root MAIL_MAILER: log steps: - uses: actions/checkout@v3 - name: Prepare The Environment run: cp .env.example .env - name: Create Database run: | sudo systemctl start mysql mysql --user="root" --password="root" -e "CREATE DATABASE `my-database` character set UTF8mb4 collate utf8mb4_bin;" - name: Install Composer Dependencies run: composer install --no-progress --prefer-dist --optimize-autoloader - name: Generate Application Key run: php artisan key:generate - name: Upgrade Chrome Driver run: php artisan dusk:chrome-driver --detect - name: Start Chrome Driver run: ./vendor/laravel/dusk/bin/chromedriver-linux & - name: Run Laravel Server run: php artisan serve --no-reload & - name: Run Dusk Tests run: php artisan dusk - name: Upload Screenshots if: failure() uses: actions/upload-artifact@v2 with: name: screenshots path: tests/Browser/screenshots - name: Upload Console Logs if: failure() uses: actions/upload-artifact@v2 with: name: console path: tests/Browser/console ``` -------------------------------- ### Running a General Statement Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/database.md Executes SQL statements that do not return a value, such as DDL statements. Use with caution. ```PHP DB::statement('drop table users'); ``` -------------------------------- ### Using Multiple Database Connections Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/database.md Accesses different database connections defined in the configuration file using the `connection` method. You can also get the raw PDO instance. ```PHP use Illuminate\Support\Facades\DB; $users = DB::connection('sqlite')->select(/* ... */); $pdo = DB::connection()->getPdo(); ``` -------------------------------- ### Create Eloquent Model Instance Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Demonstrates creating a new Eloquent model instance using the `create` method with mass assignment. This requires the model to have either `$fillable` or `$guarded` properties defined. ```PHP use App\Models\Flight; $flight = Flight::create([ 'name' => 'London to Paris', ]); ``` -------------------------------- ### Inspect Eloquent Model Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md This command allows you to inspect an Eloquent model, providing an overview of its attributes and relationships. This is useful for understanding the structure of your models. ```shell php artisan model:show Flight ``` -------------------------------- ### Flysystem 3.x Driver Prerequisites Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/upgrade.md Lists the Composer commands required to install the necessary packages for using the S3, FTP, and SFTP drivers with Flysystem 3.x. ```bash composer require -W league/flysystem-aws-s3-v3 "^3.0" ``` ```bash composer require league/flysystem-ftp "^3.0" ``` ```bash composer require league/flysystem-sftp-v3 "^3.0" ``` -------------------------------- ### Temporarily Disabling Timestamps Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Provides an example of how to perform model operations without modifying the `updated_at` timestamp using the `withoutTimestamps` method. ```PHP Model::withoutTimestamps(fn () => $post->increment(['reads'])); ``` -------------------------------- ### Create Laravel Project with Laravel Installer Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/installation.md This snippet first installs the Laravel installer globally via Composer and then uses it to create a new project named 'example-app'. ```shell composer global require laravel/installer laravel new example-app ``` -------------------------------- ### Create User Observer Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Generates a new observer class for the User model using the Artisan command. This command creates the observer file in the app/Observers directory if it doesn't exist. ```shell php artisan make:observer UserObserver --model=User ``` -------------------------------- ### Install Breeze with Blade Stack Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/starter-kits.md Scaffolds a new Laravel application with the default Blade frontend stack using the `breeze:install` Artisan command. It also includes commands to migrate the database, install npm dependencies, and compile frontend assets. ```shell php artisan breeze:install php artisan migrate npm install npm run dev ``` -------------------------------- ### Eloquent Subquery Selects Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Demonstrates using subqueries within the `addSelect` method to retrieve data from related tables in a single query. This example selects the most recently arrived flight for each destination. ```PHP use App\Models\Destination; use App\Models\Flight; return Destination::addSelect(['last_flight' => Flight::select('name') ->whereColumn('destination_id', 'destinations.id') ->orderByDesc('arrived_at') ->limit(1) ])->get(); ``` -------------------------------- ### Defining Dynamic Scopes with Parameters Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Explains how to create Eloquent scopes that accept parameters. Additional parameters are added to the scope method signature after the `$query` parameter. This example defines a `ofType` scope. ```PHP where('type', $type); } } ``` -------------------------------- ### Eloquent Subquery Ordering Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Shows how to use subqueries within the `orderBy` function to sort results based on related table data in a single query. This example sorts destinations by the arrival time of their last flight. ```PHP use App\Models\Destination; use App\Models\Flight; return Destination::orderByDesc( Flight::select('arrived_at') ->whereColumn('destination_id', 'destinations.id') ->orderByDesc('arrived_at') ->limit(1) )->get(); ``` -------------------------------- ### Basic Browser Test Example Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/dusk.md A fundamental Dusk test demonstrating how to create a browser instance, navigate to a page, fill in form fields, submit the form, and assert the resulting path. ```php create([ 'email' => 'taylor@laravel.com', ]); $this->browse(function ($browser) use ($user) { $browser->visit('/login') ->type('email', $user->email) ->type('password', 'password') ->press('Login') ->assertPathIs('/home'); }); } } ``` -------------------------------- ### Install Breeze with React Inertia Stack Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/starter-kits.md Scaffolds a new Laravel application with a React frontend stack using Inertia.js by specifying 'react' as the stack for the `breeze:install` command. ```shell php artisan breeze:install react ``` -------------------------------- ### Breeze API Installation for JavaScript Applications Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/starter-kits.md Installs Laravel Breeze with API scaffolding, suitable for authenticating JavaScript applications like Next.js or Nuxt.js. Requires setting FRONTEND_URL in .env. ```shell php artisan breeze:install api php artisan migrate ``` -------------------------------- ### Navigating and Loading Pages Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/dusk.md Demonstrates how to navigate to a page using the `visit` method and how to load a page's context using the `on` method after an action. ```php use Tests\Browser\Pages\Login; $browser->visit(new Login); ``` ```php use Tests\Browser\Pages\CreatePlaylist; $browser->visit('/dashboard') ->clickLink('Create Playlist') ->on(new CreatePlaylist) ->assertSee('@create'); ``` -------------------------------- ### Defining Local Scopes in Eloquent Models Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Demonstrates how to define reusable query constraints by prefixing model methods with `scope`. Scopes should return a query builder instance or void. This example shows scopes for 'popular' and 'active' users. ```PHP where('votes', '>', 100); } /** * Scope a query to only include active users. * * @param \Illuminate\Database\Eloquent\Builder $query * @return void */ public function scopeActive($query) { $query->where('active', 1); } } ``` -------------------------------- ### Listen for DatabaseBusy Event Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/database.md Listens for the `Illuminate\Database\Events\DatabaseBusy` event and dispatches a notification when the number of open database connections exceeds the configured threshold. This involves registering a listener in the `EventServiceProvider`. ```php use App\Notifications\DatabaseApproachingMaxConnections; use Illuminate\Database\Events\DatabaseBusy; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Notification; /** * Register any other events for your application. * * @return void */ public function boot() { Event::listen(function (DatabaseBusy $event) { Notification::route('mail', 'dev@example.com') ->notify(new DatabaseApproachingMaxConnections( $event->connectionName, $event->connections )); }); } ``` -------------------------------- ### Project Structure Example Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/vite.md Illustrates a typical project structure for a Laravel application using Vite, showing the placement of public assets and resources. ```nothing public/ taylor.png resources/ js/ Pages/ Welcome.vue images/ abigail.png ``` -------------------------------- ### PHPDoc Example Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/contributions.md An example of a valid PHPDoc block for a Laravel method, demonstrating the correct format for parameters and return types. ```php /** * Register a binding with the container. * * @param string|array $abstract * @param \Closure|string|null $concrete * @param bool $shared * @return void * * @throws \Exception */ public function bind($abstract, $concrete = null, $shared = false) { // } ``` -------------------------------- ### Retrieving or Creating Models Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Explains the `firstOrCreate` and `firstOrNew` methods. `firstOrCreate` finds a record or creates it if it doesn't exist. `firstOrNew` finds a record or instantiates a new model instance without saving it. ```PHP use AppModelsFlight; // Retrieve by name or create if not found $flight = Flight::firstOrCreate([ 'name' => 'London to Paris' ]); // Retrieve by name or create with additional attributes $flight = Flight::firstOrCreate( ['name' => 'London to Paris'], ['delayed' => 1, 'arrival_time' => '11:30'] ); ``` ```PHP use AppModelsFlight; // Retrieve by name or instantiate a new model instance $flight = Flight::firstOrNew([ 'name' => 'London to Paris' ]); // Retrieve by name or instantiate with additional attributes $flight = Flight::firstOrNew( ['name' => 'Tokyo to Sydney'], ['delayed' => 1, 'arrival_time' => '11:30'] ); // Manually save the new instance if needed // $flight->save(); ``` -------------------------------- ### Create Laravel Project with Composer Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/installation.md This command creates a new Laravel project named 'example-app' with version 9.0 or higher using Composer. ```shell composer create-project laravel/laravel:^9.0 example-app ``` -------------------------------- ### Running an Insert Statement Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/database.md Executes an SQL insert statement using the DB facade. It takes the SQL query and an array of bindings as arguments. Ensure proper binding to prevent SQL injection. ```PHP use Illuminate\Support\Facades\DB; DB::insert('insert into users (id, name) values (?, ?)', [1, 'Marc']); ``` -------------------------------- ### Install Breeze with Dark Mode Support Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/starter-kits.md Scaffolds a new Laravel application with the Blade frontend stack, including support for dark mode, by using the `--dark` directive with the `breeze:install` command. ```shell php artisan breeze:install --dark ``` -------------------------------- ### Create Laravel Project using Docker (macOS) Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/installation.md This command downloads and executes a script to create a new Laravel project named 'example-app' using Docker on macOS. It requires Docker Desktop to be installed. ```shell curl -s "https://laravel.build/example-app" | bash ``` -------------------------------- ### Setting HTTP Client Timeout Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/upgrade.md Example of how to set a custom timeout for an HTTP client request in Laravel. ```php $response = Http::timeout(120)->get(/* ... */); ``` -------------------------------- ### Fill Existing Eloquent Model Instance Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Illustrates how to use the `fill` method to populate an existing Eloquent model instance with an array of attributes. This also respects the model's `$fillable` or `$guarded` properties. ```PHP $flight->fill(['name' => 'Amsterdam to Frankfurt']); ``` -------------------------------- ### Check if Model is Soft Deleted Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Determines if a model instance has been soft deleted by checking its `deleted_at` attribute. ```PHP if ($flight->trashed()) { // Model is soft deleted } ``` -------------------------------- ### Install Laravel App with Specific Sail Services Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/installation.md Installs a new Laravel application and configures specified Sail services (e.g., MySQL, Redis) by passing them as a comma-separated list in the 'with' query parameter to the Laravel installer script. The output is piped to bash for execution. ```shell curl -s "https://laravel.build/example-app?with=mysql,redis" | bash ``` -------------------------------- ### Customizing Timestamp Format Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Shows how to customize the format of Eloquent timestamps by setting the `$dateFormat` property on the model. ```PHP forceDelete(); // Force delete via relationship $flight->history()->forceDelete(); ``` -------------------------------- ### Eloquent Soft Deletes API Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Provides an overview of the methods available for managing soft-deleted models in Laravel Eloquent. ```APIDOC SoftDeletes Trait: - Enables soft deletion for Eloquent models. - Automatically adds a `deleted_at` column. Model Methods: - `trashed()`: Returns true if the model is soft-deleted. - `restore()`: Restores a soft-deleted model. - `forceDelete()`: Permanently deletes a soft-deleted model. Query Builder Methods: - `withTrashed()`: Includes soft-deleted models in query results. - `onlyTrashed()`: Retrieves only soft-deleted models. Schema Builder Methods: - `softDeletes()`: Adds the `deleted_at` column to a table. - `dropSoftDeletes()`: Removes the `deleted_at` column from a table. ``` -------------------------------- ### Install Dusk and ChromeDriver Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/dusk.md Executes the Dusk Artisan command to set up the testing environment, create necessary directories, and install the ChromeDriver binary. ```php php artisan dusk:install ``` -------------------------------- ### Disabling Eloquent Timestamps Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Explains how to disable automatic timestamp management by setting the `$timestamps` property to `false` on the model. ```PHP nth(4); // ['a', 'e'] $collection->nth(4, 1); // ['b', 'f'] ``` -------------------------------- ### Breeze Installation with SSR Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/starter-kits.md Installs Laravel Breeze with Server-Side Rendering (SSR) support for Vue or React applications. ```shell php artisan breeze:install vue --ssr php artisan breeze:install react --ssr ``` -------------------------------- ### Connecting to Database CLI Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/database.md This snippet shows how to connect to your database's command-line interface using the `php artisan db` command. It also demonstrates how to specify a particular database connection if it's not the default one. ```shell php artisan db php artisan db mysql ``` -------------------------------- ### Delete Model Instance Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Deletes a specific model instance from the database. This method dispatches 'deleting' and 'deleted' model events. ```PHP use App\Models\Flight; $flight = Flight::find(1); $flight->delete(); ``` -------------------------------- ### Database Queue Setup Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/queues.md Provides the Artisan commands to generate the necessary migration for the database queue driver and migrate the database. It also shows how to configure the `.env` file. ```shell php artisan queue:table php artisan migrate ``` ```env QUEUE_CONNECTION=database ``` -------------------------------- ### Customizing Timestamp Column Names Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Demonstrates how to define `CREATED_AT` and `UPDATED_AT` constants on the model to use custom names for timestamp columns. ```PHP get(); $flights = $flights->reject(function ($flight) { return $flight->cancelled; }); ``` -------------------------------- ### Iterating Over Eloquent Collections Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Shows how to loop through an Eloquent Collection, treating it like a standard PHP array. Each item in the collection is an Eloquent model. ```php foreach ($flights as $flight) { echo $flight->name; } ``` -------------------------------- ### Install Laravel Telescope Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/telescope.md Installs the Laravel Telescope package using Composer and publishes its assets and migrations. ```shell composer require laravel/telescope php artisan telescope:install php artisan migrate ``` -------------------------------- ### Retrieving All Models Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Retrieves all records from a model's associated database table using the `all` method. This method returns a collection of model instances. ```php use App\Models\Flight; foreach (Flight::all() as $flight) { echo $flight->name; } ``` -------------------------------- ### Customizing UUID Generation Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Shows how to override UUID generation by defining a `newUniqueId` method and specify columns for UUIDs using the `uniqueIds` method. ```PHP use Ramsey\Uuid\Uuid; /** * Generate a new UUID for the model. * * @return string */ public function newUniqueId() { return (string) Uuid::uuid4(); } /** * Get the columns that should receive a unique identifier. * * @return array */ public function uniqueIds() { return ['id', 'discount_code']; } ``` -------------------------------- ### Podcast Model With Real-Time Facade Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/facades.md Illustrates the same Podcast model but utilizing a real-time facade for the Publisher. This eliminates the need to explicitly pass the Publisher instance, resolving it from the service container. ```php update(['publishing' => now()]); Publisher::publish($this); } } ``` -------------------------------- ### Install Laravel Breeze Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/starter-kits.md Installs the Laravel Breeze package as a development dependency in your Laravel application using Composer. ```shell composer require laravel/breeze --dev ``` -------------------------------- ### Saving a Model Without Events Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Saves a model instance without dispatching any Eloquent events. This is useful when performing operations that should not trigger observer methods. ```php use App\Models\User; $user = User::findOrFail(1); $user->name = 'Victoria Faith'; $user->saveQuietly(); ``` -------------------------------- ### Basic Controller Example Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/controllers.md Demonstrates a basic Laravel controller extending the base Controller class, handling a user profile request. It shows how to fetch a user by ID and return a view. Dependencies include the `App\Models\User` model and Laravel's `Controller` base class. ```PHP User::findOrFail($id) ]); } } ``` -------------------------------- ### Utilizing Dynamic Scopes Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Demonstrates how to call Eloquent dynamic scopes with their required arguments. The `ofType` scope is used here to retrieve users of the 'admin' type. ```PHP use App\Models\User; $users = User::ofType('admin')->get(); ``` -------------------------------- ### Migrate Database Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/fortify.md Runs database migrations to set up necessary tables for Fortify. ```shell php artisan migrate ``` -------------------------------- ### Enable Soft Deletes Trait Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Adds the `SoftDeletes` trait to an Eloquent model to enable soft deletion functionality. This automatically handles the `deleted_at` timestamp. ```PHP where('account_id', 1) ->get(); // Include soft-deleted models in relationship query $flight->history()->withTrashed()->get(); // Retrieve only soft-deleted models $flights = Flight::onlyTrashed() ->where('airline_id', 1) ->get(); ``` -------------------------------- ### Travis CI Configuration for Dusk Tests Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/dusk.md This snippet shows the `.travis.yml` configuration required to run Laravel Dusk tests on Travis CI. It includes setting up PHP, installing dependencies, generating keys, downloading the Chrome driver, and starting headless Chrome and the PHP development server. ```yaml language: php php: - 7.3 addons: chrome: stable install: - cp .env.testing .env - travis_retry composer install --no-interaction --prefer-dist - php artisan key:generate - php artisan dusk:chrome-driver before_script: - google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost & - php artisan serve --no-reload & script: - php artisan dusk ``` -------------------------------- ### Facade vs. Helper Function Equivalence Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/facades.md Demonstrates that Laravel's view creation can be achieved using either a facade or a helper function, highlighting their functional equivalence. ```PHP return Illuminate\Support\Facades\View::make('profile'); ``` ```PHP return view('profile'); ``` -------------------------------- ### Restore Soft Deleted Model Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Restores a soft-deleted model by setting its `deleted_at` attribute to null. Can be used on single instances or in mass query operations. ```PHP $flight->restore(); // Mass restore Flight::withTrashed()->where('airline_id', 1)->restore(); // Restore via relationship $flight->history()->restore(); ``` -------------------------------- ### Build and Run SSR Server Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/vite.md Provides the commands to build the SSR assets and start the SSR server using Node.js. ```sh npm run build node bootstrap/ssr/ssr.mjs ``` -------------------------------- ### Custom Table Name Source: https://github.com/pokmot/laravel-docs-v9/blob/9.x/eloquent.md Specifies a custom database table name for an Eloquent model by defining the protected $table property. This overrides the default convention. ```PHP [ 'production' => [ 'supervisor-1' => [ 'connection' => 'redis', 'queue' => ['default'], 'balance' => 'auto', 'minProcesses' => 1, 'maxProcesses' => 10, 'balanceMaxShift' => 1, 'balanceCooldown' => 3, 'tries' => 3, ], ], ] ```