Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计通过

laravel-livewireLaravel livewire 搜索

Agent Skill

laravel-livewire 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

475

周安装

20

GitHub Stars

公开资料未说明

下载量

166
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:laravel-livewire(Laravel livewire 搜索)
来源仓库:https://github.com/1naichii/ai-code-tools
仓库路径:skills/laravel-livewire
安装命令:
npx skills add https://github.com/1naichii/ai-code-tools --skill laravel-livewire
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/1naichii/ai-code-tools --skill laravel-livewire

简介

laravel-livewire 用于查找、检索和筛选相关信息。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中根据关键词快速定位候选结果。
  • 通过 npx skills add 命令从指定仓库安装并使用该技能。
  • 安装前需确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写操作。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Laravel Livewire

Overview

Build dynamic, reactive Laravel interfaces using only PHP. Livewire v4+ handles server-side rendering with automatic client-side updates via hydration/dehydration—no JavaScript required.

Quick Start

Installation

composer require livewire/livewire
php artisan livewire:layout  # Creates resources/views/layouts/app.blade.php

Create a Component

# Single-file component (default)
php artisan make:livewire CreatePost

# Page component
php artisan make:livewire pages::post.create

# Multi-file component
php artisan make:livewire CreatePost --mfc

# Class-based component (traditional)
php artisan make:livewire CreatePost --class

Basic Component Pattern

<?php
use Livewire\Component;
new class extends Component {
    public string $title = '';
    public string $content = '';

    public function save()
    {
        $this->validate([
            'title' => 'required|max:255',
            'content' => 'required',
        ]);

        Post::create($this->only(['title', 'content']));
        return $this->redirect('/posts');
    }
};
?>
<form wire:submit="save">
    <input type="text" wire:model="title">
    @error('title') <span class="error">{{ $message }}</span> @enderror

    <textarea wire:model="content"></textarea>
    @error('content') <span class="error">{{ $message }}</span> @enderror

    <button type="submit">Save</button>
</form>

Core Concepts

Component Structure

Single-file components (resources/views/components/post/⚡create.blade.php):

  • PHP class and Blade template in one file
  • Lightning bolt (⚡) is optional and can be disabled in config

Multi-file components (resources/views/components/post/⚡create/):

  • Separate files for PHP, Blade, JS, CSS
  • Better for large components with significant JavaScript

Class-based components (app/Livewire/CreatePost.php):

  • Traditional Laravel structure
  • Familiar for Livewire v2/v3 developers

Property Management

// Public properties - accessible in template as $property
public $title = '';

// Protected properties - accessible as $this->property, not sent to client
protected $apiKey = 'secret';

// Typed properties
public string $email = '';
public int $count = 0;
public ?Post $post;  // Auto-locks ID

// Reset properties
$this->reset('title', 'content');
$value = $this->pull('title');  // Get and reset

Lifecycle Hooks

HookWhen It Runs
mount()First load only - receive props/route params
boot()Every request (initial + subsequent)
hydrate()Beginning of subsequent requests
dehydrate()End of every request
updating($prop)Before property update
updated($prop)After property update
rendering()Before render()
rendered()After render()
exception($e)When exception thrown
public function mount(Post $post)
{
    $this->post = $post;
    $this->title = $post->title;
}

public function updatedTitle($value)
{
    $this->title = strtolower($value);
}

Computed Properties

Memoized derived values—accessed via $this->property.

use Livewire\Attributes\Computed;

#[Computed]
public function posts()
{
    return Post::all(); // Runs once per request
}

#[Computed(persist: true, seconds: 3600)]
public function cachedData()
{
    return ExpensiveModel::all();
}

Usage in blade: @foreach ($this->posts as $post)

Data Binding

wire:model Modifiers

ModifierBehavior
(default)Updates only on action submit
.liveUpdates as user types (150ms debounce)
.blurUpdates when user clicks away
.changeUpdates immediately on selection
.debounce.500msCustom debounce duration
.numberCast to int on server
.booleanCast to bool on server
<input type="text" wire:model="title">
<input type="email" wire:model.live="email">  <!-- Live validation -->
<input type="text" wire:model.blur="title">   <!-- On blur -->
<input type="text" wire:model.live.debounce.500ms="search">

Dependent Selects (Important!)

Use wire:key when one select depends on another.

<select wire:model.live="selectedState">
    @foreach(State::all() as $state)
        <option value="{{ $state->id }}">{{ $state->label }}</option>
    @endforeach
</select>

<select wire:model.live="selectedCity" wire:key="{{ $selectedState }}">
    @foreach(City::whereStateId($selectedState)->get() as $city)
        <option value="{{ $city->id }}">{{ $city->label }}</option>
    @endforeach
</select>

Actions & Events

Event Listeners

<button wire:click="save">Save</button>
<input wire:keydown.enter="search">
<form wire:submit="submitForm">
<button wire:click="delete({{ $post->id }})">Delete</button>

Event Modifiers

<!-- Key modifiers -->
<input wire:keydown.enter="search">
<input wire:keydown.shift.enter="...">

<!-- Event modifiers -->
<button wire:click.prevent="save">
<button wire:click.stop="...">
<button wire:click.window="...">
<button wire:click.once="...">
<button wire:click.debounce.250ms="...">

Dispatching Events

From PHP:

$this->dispatch('post-created', postId: $post->id);
$this->dispatch('post-created')->to(Dashboard::class);  // Direct to component

From Blade (client-side):

<button wire:click="$dispatch('post-created', { id: {{ $post->id }} })">

Listening in PHP:

use Livewire\Attributes\On;

#[On('post-created')]
public function handlePostCreated($postId)
{
    // Handle event
}

Listening in Blade:

<livewire:post-list @post-created="$refresh" />

Parent-Child Communication

<!-- Passing props -->
<livewire:todo-item :$post />

<!-- Reactive props (child updates when parent changes) -->
<?php
use Livewire\Attributes\Reactive;
#[Reactive]
public $todos;
?>

<!-- Direct parent access -->
<button wire:click="$parent.remove({{ $id }})">Remove</button>

Forms & Validation

Validation with Attributes

use Livewire\Attributes\Validate;

new class extends Component {
    #[Validate('required|min:5')]
    public $title = '';

    #[Validate('required|email', message: 'Please enter a valid email')]
    public $email = '';

    public function save()
    {
        $this->validate(); // Runs all rules
        Post::create($this->only(['title', 'email']));
    }
};

Real-Time Validation

<input type="text" wire:model.live="title">
@error('title') <span class="error">{{ $message }}</span> @enderror
public function updated($property)
{
    $this->validateOnly($property);
}

Form Objects

Extract form logic into reusable classes:

php artisan livewire:form PostForm
// app/Livewire/Forms/PostForm.php
namespace App\Livewire\Forms;
use Livewire\Attributes\Validate;
use Livewire\Form;

class PostForm extends Form
{
    #[Validate('required|min:5')]
    public $title = '';

    #[Validate('required|min:5')]
    public $content = '';

    public function store()
    {
        $this->validate();
        Post::create($this->only(['title', 'content']));
    }
}
<input type="text" wire:model="form.title">
@error('form.title') <span class="error">{{ $message }}</span> @enderror

Loading States

<button wire:click="save">
    Save
    <span wire:loading>Saving...</span>
</button>

<!-- Target specific action -->
<div wire:loading wire:target="removePhoto">Removing...</div>

<!-- CSS attribute -->
<button class="data-loading:opacity-50">Save</button>

Advanced Features

Lazy Loading

<livewire:revenue-chart lazy />
use Livewire\Attributes\Lazy;

#[Lazy]
class RevenueChart extends Component
{
    public function placeholder()
    {
        return view('livewire.placeholders.skeleton');
    }
}

Polling

<div wire:poll>{{ $count }}</div>           <!-- Every 2.5s -->
<div wire:poll.15s>{{ $count }}</div>       <!-- Custom interval -->
<div wire:poll.visible>{{ $count }}</div>   <!-- Only when visible -->
<div wire:poll.keep-alive>{{ $count }}</div> <!-- Keep in background -->

File Uploads

use Livewire\WithFileUploads;

class UploadPhoto extends Component
{
    use WithFileUploads;

    #[Validate('image|max:1024')] // 1MB max
    public $photo;

    public function save()
    {
        $this->photo->store(path: 'photos');
    }
}
<form wire:submit="save">
    @if ($photo)
        <img src="{{ $photo->temporaryUrl() }}">
    @endif
    <input type="file" wire:model="photo">
</form>

Pagination

use Livewire\WithPagination;

class ShowPosts extends Component
{
    use WithPagination;

    public function render()
    {
        return view('livewire.show-posts', [
            'posts' => Post::paginate(10),
        ]);
    }
}
{{ $posts->links() }}

Alpine.js Integration

<div x-data="{ expanded: false }">
    <button @click="expanded = !expanded">Toggle</button>
    <div x-show="expanded">
        {{ $content }}
    </div>
</div>

Access Livewire from Alpine:

<input x-on:blur="$wire.save()">
<span x-text="$wire.title.length"></span>

Testing

use Livewire\Livewire;

test('component renders', function () {
    Livewire::test(CreatePost::class)
        ->assertStatus(200);
});

test('can create post', function () {
    Livewire::test(CreatePost::class)
        ->set('title', 'Test Post')
        ->call('save')
        ->assertRedirect('/posts');
});

test('validation works', function () {
    Livewire::test(CreatePost::class)
        ->set('title', '')
        ->call('save')
        ->assertHasErrors('title');
});

Routing

// routes/web.php
Route::livewire('/posts/create', 'pages::post.create');
Route::livewire('/posts/{id}', 'pages::post.show');
Route::livewire('/posts/{post}', 'pages::post.edit'); // Model binding

PHP Attributes Reference

AttributePurpose
#[Validate('rule')]Add validation rules to properties
#[Computed]Create memoized derived properties
#[Computed(persist: true)]Cache computed across requests
#[Locked]Prevent client-side modification
#[Reactive]Props update when parent changes
#[On('event')]Listen for dispatched events
#[Lazy]Defer component loading
#[Session]Persist properties in session
#[Url]Sync with query string
#[Renderless]Skip re-render after action
#[Async]Execute action in parallel
#[Layout('name')]Specify custom layout
#[Title('Title')]Set page title
#[Js]Return JSON for JavaScript consumption

Common Gotchas

  1. Computed properties require $this — use $this->posts, not $posts
  2. Default wire:model doesn't update as you type — use .live modifier
  3. Dependent selects need wire:key — prevents stale options
  4. Props aren't reactive by default — use #[Reactive] attribute
  5. Always validate/authorize properties — treat as user input
  6. Use only() or except() to limit data sent to client

Security Best Practices

  1. Always authorize action parameters — users can call any public method
  2. Use #[Locked] for sensitive IDs to prevent manipulation
  3. Mark dangerous methods as protected/private — prevents client access
  4. Validate all input — use #[Validate] or rules() method
  5. Never trust client-side data — properties are user input

Performance Tips

  1. Use computed properties for expensive queries
  2. Lazy load components below the fold
  3. Use .blur instead of .live when real-time isn't needed
  4. Avoid storing large Eloquent collections as properties
  5. Use wire:key for list items to prevent DOM thrashing
  6. Debounce live updates for better performance
  7. Cache expensive operations with #[Computed(persist: true)]

Resources

For Component Architecture

See references/core.md — components, properties, lifecycle, actions

For Forms & Validation

See references/forms.md — form handling, validation, file uploads

For Advanced Features

See references/advanced.md — nesting, events, computed properties, pagination

For Directives

See references/directives.md — all wire:* directives

For Attributes

See references/attributes.md — all PHP attributes

For Integration

See references/integration.md — Alpine.js, JavaScript, security

For Testing

See references/testing.md — Pest/PHPUnit patterns

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

35.75%
按下载量换算59

Claude

32.78%
按下载量换算54

Cursor

19.5%
按下载量换算32

Gemini CLI

8.41%
按下载量换算14

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills