### Install Livewire Package with Composer
Source: https://laravel-livewire.com/docs/2.x/quickstart/1.x/reference
Installs the Livewire package into your Laravel project using Composer, making the Livewire framework available for use.
```Bash
composer require livewire/livewire
```
--------------------------------
### Install Livewire with Composer
Source: https://laravel-livewire.com/docs/2.x/quickstart/1.x/file-downloads
This command installs the Livewire package into your Laravel project using Composer, making it available for use.
```bash
composer require livewire/livewire
```
--------------------------------
### Install Livewire Package via Composer
Source: https://laravel-livewire.com/docs/2.x/quickstart/2.x/installation
This command is used to install the Livewire package into your Laravel application using Composer. It fetches the necessary dependencies and integrates Livewire into your project's vendor directory.
```Bash
composer require livewire/livewire
```
--------------------------------
### Install Livewire via Composer
Source: https://laravel-livewire.com/docs/2.x/quickstart/2.x/turbolinks
This command installs the Livewire package into your Laravel project using Composer, making the Livewire backend components and necessary dependencies available for development.
```PHP
composer require livewire/livewire
```
--------------------------------
### Publish Livewire Configuration File
Source: https://laravel-livewire.com/docs/2.x/quickstart/2.x/installation
Provides the Artisan command to publish Livewire's default configuration file, allowing users to customize various settings beyond the default 'zero-configuration' approach.
```php
php artisan livewire:publish --config
```
--------------------------------
### Install Livewire PHP Package
Source: https://laravel-livewire.com/docs/2.x/quickstart/2.x/quickstart
Use Composer to add the Livewire package to your Laravel application, making its functionalities available for use.
```Bash
composer require livewire/livewire
```
--------------------------------
### Automate Livewire Asset Publishing with Composer
Source: https://laravel-livewire.com/docs/2.x/quickstart/2.x/installation
Recommends adding the Livewire asset publishing command to the `post-autoload-dump` scripts in your `composer.json` file. This ensures assets are automatically updated and helps prevent issues during future Livewire updates.
```json
{
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi",
"@php artisan vendor:publish --force --tag=livewire:assets --ansi"
]
}
}
```
--------------------------------
### Install Livewire with Composer
Source: https://laravel-livewire.com/docs/2.x/quickstart/1.x/deployment
This command installs the Livewire package into your Laravel project using Composer, making it available for use. It's the first step to integrate Livewire into your application.
```PHP
composer require livewire/livewire
```
--------------------------------
### Install Livewire via Composer
Source: https://laravel-livewire.com/docs/2.x/quickstart/1.x/quickstart
Installs the Livewire PHP package into your Laravel project using Composer, adding it as a required dependency.
```Bash
composer require livewire/livewire
```
--------------------------------
### Install Livewire PHP Package with Composer
Source: https://laravel-livewire.com/docs/2.x/quickstart/1.x/upgrading
This command installs the Livewire PHP package into your Laravel project using Composer, making Livewire available for use.
```bash
composer require livewire/livewire
```
--------------------------------
### Publish Livewire Frontend Assets
Source: https://laravel-livewire.com/docs/2.x/quickstart/2.x/installation
Details the Artisan command to publish Livewire's JavaScript assets, enabling them to be served directly by your web server instead of through Laravel. This is useful for specific deployment scenarios.
```php
php artisan livewire:publish --assets
```
--------------------------------
### Install Livewire PHP Package via Composer
Source: https://laravel-livewire.com/docs/2.x/quickstart/quickstart
This command installs the Livewire PHP package into your Laravel project using Composer, making Livewire's backend functionalities available for use.
```PHP
composer require livewire/livewire
```
--------------------------------
### Configure Livewire Asset Base URL
Source: https://laravel-livewire.com/docs/2.x/quickstart/2.x/installation
Illustrates how to adjust the `asset_url` setting in `config/livewire.php` to resolve issues with asset loading when Livewire assets are published to a sub-folder or the application is hosted on a non-root path. Examples show common configurations.
```php
// In config/livewire.php
'asset_url' => '/assets'
// or
'asset_url' => '/application'
```
--------------------------------
### Install Livewire with Composer
Source: https://laravel-livewire.com/docs/2.x/quickstart/1.x/traits
This command installs the Livewire package into your Laravel project using Composer, making it available for use.
```bash
composer require livewire/livewire
```
--------------------------------
### Install Livewire with Composer
Source: https://laravel-livewire.com/docs/2.x/quickstart/1.x/contribution-guide
This command installs the Livewire package into your Laravel project using Composer, making it available for use.
```Composer
composer require livewire/livewire
```
--------------------------------
### Install Livewire Package via Composer
Source: https://laravel-livewire.com/docs/2.x/quickstart/index
This command installs the Livewire package into your Laravel project using Composer, the PHP dependency manager. It's the first step to integrate Livewire into your application.
```Bash
composer require livewire/livewire
```
--------------------------------
### Example Blade Layout File for Livewire
Source: https://laravel-livewire.com/docs/2.x/quickstart/2.x/rendering-components
Provides a basic example of a traditional Blade layout file, demonstrating the inclusion of `@livewireStyles` and `@livewireScripts` directives, and a `@yield('content')` placeholder for component output. This structure is compatible with Livewire's `@extends` approach.
```Blade
@livewireStyles
@yield('content')
@livewireScripts
```
--------------------------------
### Install Livewire PHP Package with Composer
Source: https://laravel-livewire.com/docs/2.x/quickstart/1.x/query-string
This command installs the Livewire PHP framework as a dependency in your Laravel project using Composer, making it available for use.
```Shell
composer require livewire/livewire
```
--------------------------------
### Install Livewire PHP Package
Source: https://laravel-livewire.com/docs/2.x/quickstart/2.x/api
This snippet demonstrates how to install the Livewire framework into your Laravel project using Composer, the PHP dependency manager. This command adds Livewire to your project's dependencies.
```PHP
composer require livewire/livewire
```
--------------------------------
### Copying Livewire Components with `copy` Command
Source: https://laravel-livewire.com/docs/2.x/quickstart/2.x/artisan-commands
Illustrates how to duplicate Livewire components using the `php artisan livewire:copy` command. It includes examples for basic copying, forcing an overwrite of an existing component, and copying with the associated test file.
```PHP
php artisan livewire:copy foo bar
# Copies Foo.php & foo.blade.php to Bar.php and bar.blade.php
php artisan livewire:copy foo bar --force
# Overwrites existing "bar" component
php artisan livewire:copy foo bar --test
# Copies Foo.php & foo.blade.php & FooTest.php to Bar.php & bar.blade.php & BarTest.php
```
--------------------------------
### Livewire Component Blade View (Example Content)
Source: https://laravel-livewire.com/docs/2.x/quickstart/1.x/file-downloads
This example demonstrates adding content to a Livewire component's Blade view. Remember that all content within a Livewire component's view must be wrapped inside a single root HTML element.
```html
Hello World!
```
--------------------------------
### Livewire Counter Component Updated Blade View
Source: https://laravel-livewire.com/docs/2.x/quickstart/1.x/reference
An updated version of the `Counter` Livewire component's Blade view, demonstrating how to add content within the required single root element. This example adds a simple 'Hello World!' heading.
```Blade
Hello World!
```
--------------------------------
### Example Blade View for Livewire Component Output
Source: https://laravel-livewire.com/docs/2.x/quickstart/2.x/rendering-components
Provides an example of a Blade view file that would be returned by a Livewire component's `render()` method. It demonstrates iterating over data and including partials, emphasizing the requirement for a single root HTML element.
```Blade
@foreach ($posts as $post)
@include('includes.post', $post)
@endforeach
```
--------------------------------
### Example Livewire Dusk Browser Test Structure
Source: https://laravel-livewire.com/docs/2.x/quickstart/2.x/contribution-guide
An example of a Livewire Dusk browser test, demonstrating how to structure a test case to interact with a Livewire component, perform actions like clicks, and assert expected outcomes in the browser.
```PHP
/** @test */
public function it_can_run_foo_action
{
$this->browse(function ($browser) {
Livewire::visit($browser, FooComponent::class)
/**
* Basic action (click).
*/
->waitForLivewire()->click('@foo')
->assertSeeIn('@output', 'foo')
;
});
}
```
--------------------------------
### Livewire Component Blade View with Basic Content
Source: https://laravel-livewire.com/docs/2.x/quickstart/2.x/quickstart
An example of adding simple content to the Livewire component's Blade view, demonstrating the single root element requirement.
```Blade
Hello World!
```
--------------------------------
### Livewire Blade View with Initial Content
Source: https://laravel-livewire.com/docs/2.x/quickstart/quickstart
Adding basic 'Hello World!' text to the Livewire component's Blade view to make something tangible visible in the browser.
```Blade
Hello World!
```
--------------------------------
### Example Livewire Component PHP Class
Source: https://laravel-livewire.com/docs/2.x/quickstart/1.x/deployment
This is the generated PHP class for the 'counter' Livewire component. It extends Livewire\Component and defines a render method responsible for returning the Blade view associated with this component.
```PHP
namespace App\Http\Livewire;
use Livewire\Component;
class Counter extends Component
{
public function render()
{
return view('livewire.counter');
}
}
```
--------------------------------
### Livewire PHP Examples for Custom File Storage
Source: https://laravel-livewire.com/docs/2.x/quickstart/1.x/file-uploads
Illustrates various methods for storing uploaded files in Livewire, leveraging Laravel's filesystem API. Examples cover storing to default/specific disks, custom filenames, and setting public visibility for uploaded files.
```PHP
// Store the uploaded file in the "photos" directory of the default filesystem disk.
$this->photo->store('photos');
// Store in the "photos" directory in a configured "s3" bucket.
$this->photo->store('photos', 's3');
// Store in the "photos" directory with the filename "avatar.png".
$this->photo->storeAs('photos', 'avatar');
// Store in the "photos" directory on S3 with the filename "avatar.png".
$this->photo->storeAs('photos', 'avatar', 'S3');
// Store in the "photos" directory, with "public" visibility in a configured "s3" bucket.
$this->photo->storePublicly('photos', 's3');
// Store in the "photos" directory, with the name "avatar.png", with "public" visibility in a configured "s3" bucket.
$this->photo->storePubliclyAs('photos', 'avatar', 's3');
```
--------------------------------
### Create Livewire Component in Sub-folders
Source: https://laravel-livewire.com/docs/2.x/quickstart/2.x/making-components
These commands demonstrate various syntaxes for creating Livewire components within sub-folders. This organizes component files into a directory structure, for example, 'app/Http/Livewire/Post/Show.php' and 'resources/views/livewire/Post/Show.blade.php'.
```php
php artisan make:livewire Post\\Show
```
```php
php artisan make:livewire Post/Show
```
```php
php artisan make:livewire post.show
```
--------------------------------
### Modified Livewire Component Blade View with Content
Source: https://laravel-livewire.com/docs/2.x/quickstart/1.x/quickstart
Illustrates how to add content to a Livewire component's Blade view file (`resources/views/livewire/counter.blade.php`). This example adds a simple 'Hello World!' heading, maintaining the requirement for a single root HTML element.
```Blade
\n
Hello World!
\n
```
--------------------------------
### Install PHP Dependencies with Composer
Source: https://laravel-livewire.com/docs/2.x/quickstart/2.x/contribution-guide
Install all required PHP dependencies for the Livewire project using Composer, ensuring all backend components are available for development and testing.
```Shell
composer install
```
--------------------------------
### Example Livewire Component PHP Class
Source: https://laravel-livewire.com/docs/2.x/quickstart/1.x/traits
This is the generated PHP class for a Livewire component. It extends Livewire\Component and defines the render method, which is responsible for returning the component's view.
```php
namespace App\Http\Livewire;
use Livewire\Component;
class Counter extends Component
{
public function render()
{
return view('livewire.counter');
}
}
```
--------------------------------
### Livewire Component PHP Class Example
Source: https://laravel-livewire.com/docs/2.x/quickstart/1.x/quickstart
Shows the basic structure of a generated Livewire component PHP class located in `app/Http/Livewire/Counter.php`. It extends `Livewire\Component` and includes a `render` method responsible for returning the component's Blade view.
```PHP
namespace App\Http\Livewire;\n\nuse Livewire\Component;\n\nclass Counter extends Component\n{\n public function render()\n {\n return view('livewire.counter');\n }\n}
```
--------------------------------
### Example of Registering a Livewire JavaScript Hook
Source: https://laravel-livewire.com/docs/2.x/quickstart/2.x/reference
Demonstrates how to register a JavaScript hook using `Livewire.hook()` to tap into specific parts of a Livewire component's JavaScript lifecycle. This example shows the `component.initialized` hook.
```JavaScript
Livewire.hook('component.initialized', component => {
//
})
```
--------------------------------
### Adding Content to Livewire Component Blade View
Source: https://laravel-livewire.com/docs/2.x/quickstart/2.x/turbolinks
An example of adding static content to the Livewire component's Blade view, demonstrating the requirement for a single root element.
```HTML
Hello World!
```
--------------------------------
### Livewire wire:click Directive Example
Source: https://laravel-livewire.com/docs/2.x/quickstart/1.x/actions
Demonstrates the basic usage of the `wire:click` directive to execute a Livewire action when a button is clicked.
```HTML
```
--------------------------------
### Rendering Livewire Components using Blade Directive
Source: https://laravel-livewire.com/docs/2.x/quickstart/2.x/artisan-commands
Illustrates how to render Livewire components within Laravel Blade files using the `@livewire('component-name')` directive. It shows examples for various component naming conventions, including fully qualified class names.
```Blade
@livewire('foo')
@livewire('foo-bar')
@livewire('foo.bar')
@livewire(Package\Livewire\Foo::class)
```
--------------------------------
### Livewire Template Directive Example
Source: https://laravel-livewire.com/docs/2.x/quickstart/2.x/reference
Demonstrates a basic Livewire template directive for handling click events on an HTML element, triggering a method in the Livewire component.
```HTML
```
--------------------------------
### Rendering Livewire Components using Tag Syntax (Laravel 7+)
Source: https://laravel-livewire.com/docs/2.x/quickstart/2.x/artisan-commands
Shows the alternative tag syntax for rendering Livewire components, which is available for Laravel 7 and newer versions. This provides a more HTML-like way to embed components.
```Blade
```
--------------------------------
### Include Livewire Assets in Blade Templates
Source: https://laravel-livewire.com/docs/2.x/quickstart/2.x/installation
Explains how to integrate Livewire's CSS and JavaScript assets into your Laravel Blade templates. It covers both the traditional Blade directive syntax and a more concise tag syntax for including styles and scripts.
```html
...
@livewireStyles
...
@livewireScripts
```
```html
...
```
--------------------------------
### Embed Livewire component and assets in a Blade layout
Source: https://laravel-livewire.com/docs/2.x/quickstart/2.x/api
This example shows how to integrate a Livewire component into any Blade view using its tag-like syntax. It also includes the essential `@livewireStyles` and `@livewireScripts` directives for Livewire to function correctly.
```HTML
...
@livewireStyles
...
@livewireScripts