Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MislavNovalic's avatar

Error when I click on a form button

In the episode 6 "Build LivewireApp with me" I cannot make request when I click the button 'Create listening party', app breaks with the following error :

Livewire\Exceptions\MissingRulesException
Missing [$rules/rules()] property/method on: [dashboard].

dashboard.blade.php :

<?php

use Livewire\Volt\Component;
use App\Models\ListeningParty;
use Livewire\Attibutes\Validate;
use App\Models\Episode;

new class extends Component {

   #[Validate('required|string|max:255')]
   public string $name = '';
   #[Validate('required')]
   public $startTime;
   #[Validate('required|url')]
   public string $mediaUrl = '';


   public function createListeningParty()
   {

    $this->validate();

      $episode = Episode::create([
            'media_url' => $this->mediaUrl,
        ]);

      $listeningParty = ListeningParty::create([
            'episode_id' => $episode->id,
            'name' => $this->name,
            'start_time' => $this->startTime,
        ]);  

        return redirect()->route('parties.show', $listeningParty);


   }



    public function with()
    {
        return [

            'listening_parties' => ListeningParty::all(),
        ];
    }
}; ?>

 <div class="flex items-center justify-center min-h-screen bg-slate-60">
     <div class="max-w-lg w-full px-4">
         <form wire:submit ='createListeningParty' class="space-y-6"> 
         <x-input wire:model='name' placeholder="Listeining Party Name" />
         <x-input wire:model='mediaUrl' placeholder="Podcast Episode URL" description="Direct 
episode link or Youtube link, RSS feeds will grab the latest episode" />
        <x-datetime-picker wire:model='startTime' placeholder="Listeining Party Name Start Time" /> 
        <x-button primary type="submit">Create Listening Party </x-button> 
        </form>
    </div>      
</div>

Please advise.

0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

The error you're encountering, Livewire\Exceptions\MissingRulesException, indicates that Livewire is expecting validation rules to be defined, but it can't find them. This is likely because the #[Validate] attribute is not being recognized as a valid way to define validation rules in your Livewire component.

To resolve this issue, you should define a rules() method in your Livewire component to specify the validation rules. Here's how you can modify your component to include the rules() method:

Key Changes:

  1. Removed the #[Validate] attributes: These are not standard in Livewire and are likely causing the issue.
  2. Added a rules() method: This method returns an array of validation rules that Livewire will use when you call $this->validate().

Make sure your Livewire component is correctly set up to use these rules, and this should resolve the error you're experiencing.

1 like

Please or to participate in this conversation.