DeveloperBreeze

Tutorials Programming Tutorials, Guides & Best Practices

Explore 149+ expertly crafted tutorials tutorials, components, and code examples. Stay productive and build faster with proven implementation strategies and design patterns from DeveloperBreeze.

Managing WYSIWYG Editors with Livewire: A Step-by-Step Guide

Tutorial August 14, 2024
javascript php

    namespace App\Http\Livewire;

    use Livewire\Component;

    class EditorComponent extends Component
    {
        public $content = '';

        protected $listeners = ['updateContent'];

        public function updateContent($wireId, $newContent)
        {
            $this->content = $newContent;
        }

        public function render()
        {
            return view('livewire.editor-component');
        }
    }

Here, we’ve defined a content property to store the editor’s content. The updateContent method listens for updates from the front-end and sets the content accordingly.

Implementing Real-Time Search with Livewire in Laravel

Tutorial August 14, 2024
javascript php

Open the newly created SearchPosts.php file and set up the properties and methods to manage the search query and results:

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use App\Models\Post;

class SearchPosts extends Component
{
    public $query = '';
    public $posts = [];

    public function updatedQuery()
    {
        $this->posts = Post::where('title', 'like', '%' . $this->query . '%')->get();
    }

    public function render()
    {
        return view('livewire.search-posts');
    }
}

Dynamically Updating Form Fields with Livewire in Laravel

Tutorial August 14, 2024
php

Next, create the Blade view for this component in resources/views/livewire/dynamic-form.blade.php.

<div>
    <!-- Category Dropdown -->
    <label for="category">Category:</label>
    <select id="category" wire:model="selectedCategory">
        <option value="">Select a category</option>
        @foreach($categories as $category)
            <option value="{{ $category }}">{{ ucfirst($category) }}</option>
        @endforeach
    </select>

    <!-- Subcategory Dropdown -->
    @if(!empty($subcategories))
        <label for="subcategory" class="mt-4">Subcategory:</label>
        <select id="subcategory">
            <option value="">Select a subcategory</option>
            @foreach($subcategories as $subcategory)
                <option value="{{ $subcategory }}">{{ $subcategory }}</option>
            @endforeach
        </select>
    @endif
</div>

Managing Modals with Livewire and JavaScript

Tutorial August 14, 2024
javascript php

When using Livewire, it's common to encounter issues with JavaScript-based interactions, such as modals, due to Livewire's re-rendering of the DOM. This tutorial will guide you through using Livewire's event system to handle modals more effectively.

  • Basic understanding of Livewire and JavaScript
  • A Laravel project with Livewire installed