### Install Laravel Dusk and ChromeDriver
Source: https://laravel.com/docs/9.x/dusk
Run the dusk:install Artisan command to create the tests/Browser directory, an example test, and install the ChromeDriver binary.
```shell
php artisan dusk:install
```
--------------------------------
### Basic PHPUnit Test Example
Source: https://laravel.com/docs/9.x/testing
A simple example of a PHPUnit test case. Remember to call `parent::setUp()` and `parent::tearDown()` if you define your own setup or teardown methods.
```php
assertTrue(true);
}
}
```
--------------------------------
### Install Laravel Installer and Create Project
Source: https://laravel.com/docs/9.x
Globally install the Laravel installer via Composer, then use the `laravel new` command to create a new project. This is an alternative to using `composer create-project` directly.
```bash
composer global require laravel/installer
```
```bash
laravel new example-app
```
--------------------------------
### Install PHP with Homebrew
Source: https://laravel.com/docs/9.x/valet
Install PHP using Homebrew, a prerequisite for Valet.
```shell
brew install php
```
--------------------------------
### Install Valet and Configure Services
Source: https://laravel.com/docs/9.x/valet
Run the Valet install command to configure Valet and DnsMasq. This also sets up Valet to launch on system startup.
```shell
valet install
```
--------------------------------
### Install Telescope Assets and Run Migrations
Source: https://laravel.com/docs/9.x/telescope
After installing the package, run these Artisan commands to publish Telescope's assets and create the necessary database tables.
```shell
php artisan telescope:install
php artisan migrate
```
--------------------------------
### Install Laravel Breeze with React
Source: https://laravel.com/docs/9.x/starter-kits
Use this command to scaffold a new Laravel application with Breeze and the React frontend stack. After installation, run `php artisan migrate`, `npm install`, and `npm run dev` to set up the project.
```shell
php artisan breeze:install react
```
--------------------------------
### Install Passport and Generate Keys
Source: https://laravel.com/docs/9.x/passport
Execute the passport:install command to generate encryption keys for secure access tokens and create initial clients.
```shell
php artisan passport:install
```
--------------------------------
### Start Homestead VM
Source: https://laravel.com/docs/9.x/homestead
After updating configuration files, regenerate and start your Homestead virtual machine with `vagrant up`.
```shell
vagrant up
```
--------------------------------
### GitHub Actions Workflow for Dusk Tests
Source: https://laravel.com/docs/9.x/dusk
This GitHub Actions workflow automates Dusk test execution on Ubuntu. It sets up the environment, creates a database, installs dependencies, and starts the Chrome driver and Laravel server.
```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
```
--------------------------------
### Start Octane Server with File Watching
Source: https://laravel.com/docs/9.x/octane
Use the --watch flag to automatically restart the Octane server when application files change. Ensure Node.js and Chokidar are installed.
```shell
php artisan octane:start --watch
```
--------------------------------
### Ensure String Starts with a Value
Source: https://laravel.com/docs/9.x/helpers
The `start` method prepends a given value to a string only if it doesn't already start with it. This is useful for ensuring paths or prefixes.
```php
use Illuminate\Support\Str;
$adjusted = Str::of('this/string')->start('/');
// /this/string
$adjusted = Str::of('/this/string')->start('/');
// /this/string
```
--------------------------------
### Dev Server URL Transformation Example
Source: https://laravel.com/docs/9.x/vite
This example shows the difference in image source URLs before and after applying the `transformOnServe` configuration to correct dev server paths.
```html
-
+
```
--------------------------------
### Install Node.js Dependencies
Source: https://laravel.com/docs/9.x/starter-kits
Install all necessary Node.js packages for your frontend assets after installing Breeze.
```shell
npm install
```
--------------------------------
### Install Laravel Cashier
Source: https://laravel.com/docs/9.x/billing
Install the Cashier package using Composer. Remember to set up webhook handling after installation.
```shell
composer require laravel/cashier
```
--------------------------------
### Install Flysystem SFTP Package
Source: https://laravel.com/docs/9.x/filesystem
Install the Flysystem SFTP package using Composer before configuring the SFTP driver.
```shell
composer require league/flysystem-sftp-v3 "^3.0"
```
--------------------------------
### Install Packages Avoiding Configuration Prompts
Source: https://laravel.com/docs/9.x/homestead
Use this command within `after.sh` or `user-customizations.sh` to install packages without interactive prompts, preserving existing configurations.
```shell
sudo apt-get -y \
-o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confold" \
install package-name
```
--------------------------------
### Install Flysystem FTP Package
Source: https://laravel.com/docs/9.x/filesystem
Install the Flysystem FTP package using Composer before configuring the FTP driver.
```shell
composer require league/flysystem-ftp "^3.0"
```
--------------------------------
### Install Laravel Telescope
Source: https://laravel.com/docs/9.x/telescope
Use Composer to add Telescope to your project. This command installs the package for general use.
```shell
composer require laravel/telescope
```
--------------------------------
### Start Laravel Sail
Source: https://laravel.com/docs/9.x/installation
Navigate to your project directory and start the Laravel Sail development server. This command starts the application's Docker containers.
```shell
cd example-app
./vendor/bin/sail up
```
--------------------------------
### Install Supervisor on Ubuntu
Source: https://laravel.com/docs/9.x/horizon
Use this command to install Supervisor, a process monitor that automatically restarts the Horizon process if it fails.
```shell
sudo apt-get install supervisor
```
--------------------------------
### Install @vitejs/plugin-react
Source: https://laravel.com/docs/9.x/vite
Install the React plugin for Vite using npm.
```sh
npm install --save-dev @vitejs/plugin-react
```
--------------------------------
### Install Sail with Devcontainer Support
Source: https://laravel.com/docs/9.x/sail
Install Sail and publish a default `.devcontainer/devcontainer.json` file to enable development within a Devcontainer environment.
```shell
php artisan sail:install --devcontainer
```
--------------------------------
### Install MeiliSearch SDKs
Source: https://laravel.com/docs/9.x/scout
For the MeiliSearch driver, install the MeiliSearch PHP SDK and a compatible HTTP factory implementation. Review MeiliSearch's documentation for binary compatibility.
```shell
composer require meilisearch/meilisearch-php http-interop/http-factory-guzzle
```
--------------------------------
### Switch PHP Versions with Valet
Source: https://laravel.com/docs/9.x/valet
Use the `valet use` command to switch between installed PHP versions. Valet will install the specified version via Homebrew if it's not already present.
```shell
valet use php@7.2
```
```shell
valet use php
```
--------------------------------
### Install Ably PHP SDK
Source: https://laravel.com/docs/9.x/broadcasting
Install the Ably PHP SDK using Composer. This is required if you plan to broadcast events using Ably.
```shell
composer require ably/ably-php
```
--------------------------------
### Start Sail Development Environment
Source: https://laravel.com/docs/9.x/sail
Start the Docker containers for your Laravel Sail development environment. This command is typically run after installing and configuring Sail.
```shell
./vendor/bin/sail up
```
--------------------------------
### Start Laravel Development Server
Source: https://laravel.com/docs/9.x
After creating your Laravel project, navigate into the project directory and use the Artisan CLI to start the local development server. Your application will be accessible at http://localhost:8000.
```bash
cd example-app
php artisan serve
```
--------------------------------
### Install AWS SDK for PHP
Source: https://laravel.com/docs/9.x/mail
Install the AWS SDK for PHP using Composer to enable the SES mail driver.
```shell
composer require aws/aws-sdk-php
```
--------------------------------
### Install Chokidar File Watching Library
Source: https://laravel.com/docs/9.x/octane
Install the Chokidar library as a development dependency to enable file watching for the Octane server.
```shell
npm install --save-dev chokidar
```
--------------------------------
### Start Queue Worker for Specific Connection
Source: https://laravel.com/docs/9.x/queues
Use this command to start a queue worker that utilizes a specific connection defined in `config/queue.php`. For example, to use the 'redis' connection.
```shell
php artisan queue:work redis
```
--------------------------------
### Podcast Model With Real-Time Facades
Source: https://laravel.com/docs/9.x/facades
This example demonstrates using a real-time facade for the Publisher class. The Publisher instance is resolved from the service container, and no explicit injection is needed in the publish method.
```php
update(['publishing' => now()]);
Publisher::publish($this);
}
}
```
--------------------------------
### Extract Substring with Str::substr()
Source: https://laravel.com/docs/9.x/helpers
Use `Str::substr` to get a portion of a string based on start position and length. Requires importing `Illuminate\Support\Str`.
```php
use Illuminate\Support\Str;
$converted = Str::substr('The Laravel Framework', 4, 7);
```
--------------------------------
### Install doctrine/dbal for DatabaseTruncation
Source: https://laravel.com/docs/9.x/dusk
Install the doctrine/dbal package via Composer to enable the DatabaseTruncation trait for faster test database resets.
```shell
composer require --dev doctrine/dbal
```
--------------------------------
### Get RoadRunner Binary within Sail
Source: https://laravel.com/docs/9.x/octane
Start a Sail shell and use the 'rr' executable to download the latest Linux build of the RoadRunner binary.
```shell
./vendor/bin/sail shell
# Within the Sail shell...
./vendor/bin/rr get-binary
```
--------------------------------
### Setup Directive for PHP Code
Source: https://laravel.com/docs/9.x/envoy
Use the @setup directive to execute arbitrary PHP code before running Envoy tasks. This can be used for variable initialization.
```php
@setup
$now = new DateTime;
@endsetup
```
--------------------------------
### Park a Directory with Valet
Source: https://laravel.com/docs/9.x/valet
Use the `park` command to register a directory containing your applications. All subdirectories will then be accessible via `http://.test`.
```shell
cd ~/
Sites
valet park
```
--------------------------------
### Listen for Public Channel Events
Source: https://laravel.com/docs/9.x/broadcasting
Use the `channel` method to get a channel instance and `listen` to subscribe to events. Ensure Laravel Echo is installed and instantiated.
```javascript
Echo.channel(`orders.${this.order.id}`)
.listen('OrderShipmentStatusUpdated', (e) => {
console.log(e.order.name);
});
```
--------------------------------
### Install ChromeDriver for All OS
Source: https://laravel.com/docs/9.x/dusk
Use the --all flag with the dusk:chrome-driver command to install ChromeDriver for all supported operating systems.
```shell
php artisan dusk:chrome-driver --all
```
--------------------------------
### Retrieve All Users
Source: https://laravel.com/docs/9.x/queries
Use the DB facade's table method to start a query and the get method to retrieve all rows. Results are returned as a collection of stdClass objects.
```php
get();
return view('user.index', ['users' => $users]);
}
}
```
```php
use Illuminate\Support\Facades\DB;
$users = DB::table('users')->get();
foreach ($users as $user) {
echo $user->name;
}
```
--------------------------------
### Configure FTP Filesystem
Source: https://laravel.com/docs/9.x/filesystem
Sample configuration for an FTP filesystem. Ensure environment variables for host, username, and password are set.
```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,
],
```
--------------------------------
### Publish Horizon Assets
Source: https://laravel.com/docs/9.x/horizon
After installation, publish Horizon's assets using the `horizon:install` Artisan command. This sets up necessary files and configurations.
```shell
php artisan horizon:install
```
--------------------------------
### Retrieve Attributes Starting With a String
Source: https://laravel.com/docs/9.x/blade
Use `whereStartsWith` to get all attributes whose keys begin with a specified string. Useful for filtering attributes like `wire:model`.
```blade
{{ $attributes->whereStartsWith('wire:model') }}
```
--------------------------------
### Create New Laravel Project on Windows (WSL2)
Source: https://laravel.com/docs/9.x
Execute this command within a WSL2 Linux terminal session to create a new Laravel project. Customize 'example-app' as needed, adhering to naming conventions (alphanumeric, dashes, underscores).
```bash
curl -s https://laravel.build/example-app | bash
```
--------------------------------
### Install Dropbox Flysystem Adapter
Source: https://laravel.com/docs/9.x/filesystem
Use Composer to install the community-maintained Dropbox adapter for Flysystem. This is the first step to creating a custom Dropbox filesystem driver.
```shell
composer require spatie/flysystem-dropbox
```
--------------------------------
### Install Flysystem Path Prefixing Package
Source: https://laravel.com/docs/9.x/filesystem
Install the Flysystem Path Prefixing package via Composer to enable scoped filesystems.
```shell
composer require league/flysystem-path-prefixing "^3.0"
```
--------------------------------
### Implement Custom Json Cast
Source: https://laravel.com/docs/9.x/eloquent-mutators
Custom cast classes must implement the `CastsAttributes` interface, defining `get` and `set` methods. The `get` method transforms database values to cast values, and the `set` method transforms cast values to database values. This example re-implements the built-in `json` cast.
```php
$value->lineOne,
'address_line_two' => $value->lineTwo,
];
}
}
```
--------------------------------
### Create a Directory
Source: https://laravel.com/docs/9.x/filesystem
Create a directory, including any necessary parent directories, using the `makeDirectory` method.
```php
Storage::makeDirectory($directory);
```
--------------------------------
### Initiate Guest Checkout Session
Source: https://laravel.com/docs/9.x/billing
Use `Checkout::guest()->create()` to start a checkout session for a guest user. Ensure you provide valid success and cancel URLs.
```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 Envoy
Source: https://laravel.com/docs/9.x/envoy
Install Envoy using Composer. It is recommended to install it as a development dependency.
```shell
composer require laravel/envoy --dev
```
--------------------------------
### Create Subscription with Coupon
Source: https://laravel.com/docs/9.x/cashier-paddle
Apply a coupon to a new subscription by using the `withCoupon` method before calling `create`.
```PHP
$payLink = $user->newSubscription('default', $monthly = 12345)
->returnTo(route('home'))
->withCoupon('code')
->create();
```
--------------------------------
### Livewire Counter Component Example
Source: https://laravel.com/docs/9.x/frontend
Define a Livewire component with public properties and methods to manage UI state and actions. This example shows a simple counter.
```php
count++;
}
public function render()
{
return view('livewire.counter');
}
}
```
--------------------------------
### Start Octane Server
Source: https://laravel.com/docs/9.x/octane
Use this Artisan command to start the Octane server. By default, it uses the server specified in your octane configuration file and runs on port 8000.
```shell
php artisan octane:start
```
--------------------------------
### Configure SFTP Filesystem
Source: https://laravel.com/docs/9.x/filesystem
Sample configuration for an SFTP filesystem. Supports both basic and SSH key-based authentication. Ensure relevant environment variables are set.
```php
'sftp' => [
'driver' => 'sftp',
'host' => env('SFTP_HOST'),
// Settings for basic authentication...
'username' => env('SFTP_USERNAME'),
'password' => env('SFTP_PASSWORD'),
// Settings for SSH key based authentication with encryption password...
'privateKey' => env('SFTP_PRIVATE_KEY'),
'passphrase' => env('SFTP_PASSPHRASE'),
// Optional SFTP Settings...
// 'hostFingerprint' => env('SFTP_HOST_FINGERPRINT'),
// 'maxTries' => 4,
// 'passphrase' => env('SFTP_PASSPHRASE'),
// 'port' => env('SFTP_PORT', 22),
// 'root' => env('SFTP_ROOT', ''),
// 'timeout' => 30,
// 'useAgent' => true,
],
```
--------------------------------
### Install Laravel Homestead with Composer
Source: https://laravel.com/docs/9.x/homestead
Install Homestead into your project using Composer as a development dependency. This allows for per-project installations of Homestead.
```shell
composer require laravel/homestead --dev
```
--------------------------------
### Reset Valet Installation
Source: https://laravel.com/docs/9.x/valet
To reset your Valet installation and potentially solve issues, run `composer global require laravel/valet` followed by `valet install`.
```shell
composer global require laravel/valet
valet install
```
--------------------------------
### Render a View with Data using `View` Facade
Source: https://laravel.com/docs/9.x/views
Alternatively, use the `View` facade to make views available. This requires importing the facade.
```php
use Illuminate\Support\Facades\View;
return View::make('greeting', ['name' => 'James']);
```
--------------------------------
### Configure Scoped Filesystem
Source: https://laravel.com/docs/9.x/filesystem
Create a path-scoped filesystem instance by defining a disk that utilizes the 'scoped' driver. This example scopes an 's3' disk to a specific path prefix.
```php
's3-videos' => [
'driver' => 'scoped',
'disk' => 's3',
'prefix' => 'path/to/videos',
],
```
--------------------------------
### GET Request with Query Parameters
Source: https://laravel.com/docs/9.x/http-client
Append query parameters to a GET request by passing an array of key/value pairs as the second argument to the `get` method.
```php
$response = Http::get('http://example.com/users', [
'name' => 'Taylor',
'page' => 1,
]);
```
--------------------------------
### Run Envoy Binary
Source: https://laravel.com/docs/9.x/envoy
After installation, the Envoy binary is available in your project's vendor/bin directory.
```shell
php vendor/bin/envoy
```
--------------------------------
### Navigate and Start Laravel Sail on macOS
Source: https://laravel.com/docs/9.x
After creating the project, navigate to the application directory and start the Sail environment. This command starts the Docker containers for your Laravel application.
```bash
cd example-app
./vendor/bin/sail up
```
--------------------------------
### Create Subscription with Trial (Upfront Payment)
Source: https://laravel.com/docs/9.x/billing
When creating a subscription with payment details collected upfront, use `trialDays` to set a trial period. Users will not be billed until the trial expires. Ensure users are notified before the trial ends to avoid unexpected charges.
```php
use Illuminate\Http\Request;
Route::post('/user/subscribe', function (Request $request) {
$request->user()->newSubscription('default', 'price_monthly')
->trialDays(10)
->create($request->paymentMethodId);
// ...
});
```
--------------------------------
### Configure Pint with a JSON File
Source: https://laravel.com/docs/9.x/pint
Create a pint.json file in your project root to customize Pint's behavior. This example sets the preset to 'laravel'.
```json
{
"preset": "laravel"
}
```
--------------------------------
### Install @vitejs/plugin-vue
Source: https://laravel.com/docs/9.x/vite
Install the Vue plugin for Vite using npm.
```sh
npm install --save-dev @vitejs/plugin-vue
```
--------------------------------
### Confirm Card Setup with Stripe.js
Source: https://laravel.com/docs/9.x/billing
Use Stripe.js to confirm the card setup using the client secret obtained from the Setup Intent. This securely retrieves a payment method identifier from Stripe.
```javascript
const cardHolderName = document.getElementById('card-holder-name');
const cardButton = document.getElementById('card-button');
const clientSecret = cardButton.dataset.secret;
cardButton.addEventListener('click', async (e) => {
const { setupIntent, error } = await stripe.confirmCardSetup(
clientSecret, {
payment_method: {
card: cardElement,
billing_details: { name: cardHolderName.value }
}
}
);
if (error) {
// Display "error.message" to the user...
} else {
// The card has been verified successfully...
}
});
```
--------------------------------
### Define HTTP Client Macro
Source: https://laravel.com/docs/9.x/http-client
Create reusable HTTP client configurations by defining macros in the `App\Providers\AppServiceProvider`'s `boot` method. This example configures a macro for GitHub requests.
```php
use Illuminate\Support\Facades\Http;
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Http::macro('github', function () {
return Http::withHeaders([
'X-Example' => 'example',
])->baseUrl('https://github.com');
});
}
```
--------------------------------
### Show Database Overview with Artisan
Source: https://laravel.com/docs/9.x/database
The `db:show` Artisan command provides an overview of your database, including tables, size, and connections. Use `--database` to specify a connection.
```shell
php artisan db:show
```
```shell
php artisan db:show --database=pgsql
```
```shell
php artisan db:show --counts --views
```
--------------------------------
### Build and Run SSR Server
Source: https://laravel.com/docs/9.x/vite
Commands to build the SSR assets and start the SSR server.
```sh
npm run build
node bootstrap/ssr/ssr.mjs
```
--------------------------------
### Install Laravel Sanctum
Source: https://laravel.com/docs/9.x/sanctum
Install Sanctum using Composer. This command adds the package to your project.
```shell
composer require laravel/sanctum
```
--------------------------------
### Install Laravel Breeze
Source: https://laravel.com/docs/9.x/starter-kits
Install the Laravel Breeze package as a development dependency using Composer.
```shell
composer require laravel/breeze --dev
```
--------------------------------
### Share Site via Expose
Source: https://laravel.com/docs/9.x/valet
If Expose is installed, navigate to the site's directory and run the `expose` command to share your site. Press `Control + C` to stop sharing.
```shell
cd ~/Sites/laravel
expose
```
--------------------------------
### Start Queue Listener
Source: https://laravel.com/docs/9.x/queues
Start a queue listener using the `queue:listen` Artisan command. This command reloads application state and code changes automatically but is less efficient than `queue:work`.
```shell
php artisan queue:listen
```
--------------------------------
### Install Laravel Tinker
Source: https://laravel.com/docs/9.x/artisan
Install the Laravel Tinker package using Composer if it has been removed from your application.
```shell
composer require laravel/tinker
```
--------------------------------
### Generate a Policy with Model Examples
Source: https://laravel.com/docs/9.x/authorization
Use the `--model` option with the `make:policy` Artisan command to generate a policy class pre-populated with example methods for common resource actions (view, create, update, delete).
```Shell
php artisan make:policy PostPolicy --model=Post
```
--------------------------------
### Install vite-plugin-manifest-sri
Source: https://laravel.com/docs/9.x/vite
Install this NPM package to enable Subresource Integrity (SRI) hashing for your Vite-generated assets.
```shell
npm install --save-dev vite-plugin-manifest-sri
```
--------------------------------
### Install Dompdf Library
Source: https://laravel.com/docs/9.x/billing
Use Composer to install the Dompdf library, which is required for generating invoice PDFs.
```bash
composer require dompdf/dompdf
```
--------------------------------
### Str::start()
Source: https://laravel.com/docs/9.x/helpers
Adds a single instance of the given value to a string if it does not already start with that value.
```APIDOC
## Str::start()
### Description
Adds a single instance of the given value to a string if it does not already start with that value.
### Method
`static`
### Parameters
None
### Request Example
```php
use Illuminate\Support\Str;
$adjusted = Str::start('this/string', '/');
```
### Response
```
'/this/string'
```
```
--------------------------------
### Install Laravel Horizon
Source: https://laravel.com/docs/9.x/horizon
Install Horizon using Composer. This command adds the Horizon package to your project.
```shell
composer require laravel/horizon
```
--------------------------------
### Basic Browser Test Example
Source: https://laravel.com/docs/9.x/dusk
A fundamental Dusk test demonstrating user login. It navigates to the login page, fills in credentials, submits the form, and asserts the redirection to the home page.
```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');
});
}
}
```
--------------------------------
### Prepend Text to File
Source: https://laravel.com/docs/9.x/filesystem
Add content to the beginning of an existing file. If the file does not exist, it will be created.
```php
Storage::prepend('file.log', 'Prepended Text');
```
--------------------------------
### Install Vonage Notification Channel
Source: https://laravel.com/docs/9.x/notifications
Install the `laravel/vonage-notification-channel` and `guzzlehttp/guzzle` packages using Composer to enable SMS notifications.
```bash
composer require laravel/vonage-notification-channel guzzlehttp/guzzle
```
--------------------------------
### Podcast Model Without Real-Time Facades
Source: https://laravel.com/docs/9.x/facades
This example shows a Podcast model that requires explicit injection of a Publisher instance. This method allows for easy testing by mocking the injected dependency.
```php
update(['publishing' => now()]);
$publisher->publish($this);
}
}
```
--------------------------------
### Install PSR-7 Libraries
Source: https://laravel.com/docs/9.x/requests
Install the Symfony HTTP Message Bridge and nyholm/psr7 libraries to use PSR-7 requests.
```shell
composer require symfony/psr-http-message-bridge
composer require nyholm/psr7
```
--------------------------------
### Install Postmark Mailer Transport
Source: https://laravel.com/docs/9.x/mail
Install the Postmark Mailer transport and HTTP client for using the Postmark driver.
```shell
composer require symfony/postmark-mailer symfony/http-client
```
--------------------------------
### Install Mailgun Mailer Transport
Source: https://laravel.com/docs/9.x/mail
Install the Mailgun Mailer transport and HTTP client for using the Mailgun driver.
```shell
composer require symfony/mailgun-mailer symfony/http-client
```
--------------------------------
### Display Application Overview with Artisan
Source: https://laravel.com/docs/9.x/configuration
Use the 'about' Artisan command to quickly view your application's configuration, drivers, and environment. Filter the output for specific sections using the '--only' option.
```shell
php artisan about
```
```shell
php artisan about --only=environment
```
--------------------------------
### Install Octane and RoadRunner with Sail
Source: https://laravel.com/docs/9.x/octane
When developing with Laravel Sail, use these commands to install Octane and the RoadRunner binary.
```shell
./vendor/bin/sail up
./vendor/bin/sail composer require laravel/octane spiral/roadrunner
```
--------------------------------
### Run Default Database Seeder
Source: https://laravel.com/docs/9.x/seeding
Execute the default database seeder class. This is useful for populating your database with initial data.
```shell
php artisan db:seed
```
--------------------------------
### Install Latest ChromeDriver
Source: https://laravel.com/docs/9.x/dusk
Use the dusk:chrome-driver command to install the latest version of ChromeDriver for your operating system.
```shell
php artisan dusk:chrome-driver
```
--------------------------------
### Install Laravel Fortify
Source: https://laravel.com/docs/9.x/fortify
Install Fortify using Composer. This is the first step to integrating Fortify into your Laravel application.
```shell
composer require laravel/fortify
```
--------------------------------
### Using Cache Facade in Controller
Source: https://laravel.com/docs/9.x/facades
Illustrates how to use the Cache facade within a controller to retrieve user data. This example requires the Cache facade to be imported.
```php
$user]);
}
}
```
--------------------------------
### Testing Real-Time Facades with Mocking
Source: https://laravel.com/docs/9.x/facades
This example shows how to test a method that uses a real-time facade. Laravel's testing helpers allow you to mock the facade's methods, ensuring that the expected interactions occur during the test.
```php
create();
Publisher::shouldReceive('publish')->once()->with($podcast);
$podcast->publish();
}
}
```
--------------------------------
### Start Horizon Process
Source: https://laravel.com/docs/9.x/horizon
Use this Artisan command to start all configured Horizon worker processes for the current environment.
```shell
php artisan horizon
```
--------------------------------
### Create Stripe Setup Intent
Source: https://laravel.com/docs/9.x/billing
Create a Stripe Setup Intent to securely gather customer payment method details for future use with subscriptions. This method should be called from the view that renders the payment method form.
```php
return view('update-payment-method', [
'intent' => $user->createSetupIntent()
]);
```
--------------------------------
### Define a Basic GET Route
Source: https://laravel.com/docs/9.x/routing
Register a route that responds to GET requests with a specific URI and executes a closure.
```php
use Illuminate\Support\Facades\Route;
Route::get('/greeting', function () {
return 'Hello World';
});
```
--------------------------------
### Install Laravel Passport
Source: https://laravel.com/docs/9.x/passport
Install the Passport package using Composer. This is the first step to integrating Passport into your Laravel application.
```shell
composer require laravel/passport
```
--------------------------------
### Build Log Stack Configuration
Source: https://laravel.com/docs/9.x/logging
Example configuration for a 'stack' log channel that aggregates messages from 'syslog' and 'slack' channels. Messages are processed by each channel in the stack.
```php
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['syslog', 'slack'],
],
'syslog' => [
'driver' => 'syslog',
'level' => 'debug',
],
'slack' => [
'driver' => 'slack',
'url' => env('LOG_SLACK_WEBHOOK_URL'),
'username' => 'Laravel Log',
'emoji' => ':boom:',
'level' => 'critical',
],
],
```
--------------------------------
### Local Only Installation of Laravel Telescope
Source: https://laravel.com/docs/9.x/telescope
Install Telescope as a development dependency. This is recommended if Telescope will only be used in local development environments.
```shell
composer require laravel/telescope --dev
php artisan telescope:install
php artisan migrate
```
--------------------------------
### Provide Auto-Completion Hints
Source: https://laravel.com/docs/9.x/artisan
Use the `anticipate` method to offer auto-completion suggestions for user input. The user can still enter custom text.
```php
$name = $this->anticipate('What is your name?', ['Taylor', 'Dayle']);
```
--------------------------------
### Create Post Controller with Create and Store Methods
Source: https://laravel.com/docs/9.x/validation
A basic controller to handle the routes for creating and storing blog posts. The `store` method is left empty for validation logic to be added.
```PHP