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

bobvin042's avatar

The blade not calling a function in the component

I hava a modal within a blade view(criteria.blade.php and i want this modal when triggered and filled to call the function with a component(Criteria.php) which sends data to the database but the function saveCriteria() is not being called and unfortunately the database is not being populated with the new data. Please help me out

//criterias.blade.php

" <flux:modal name="add-criteria" class="md:w-96"> <flux:heading size="lg" class="text-sky-600">Add Criteria</flux:heading> <flux:text class="mt-2">Add New Criteria for Assessment</flux:text>

        <flux:input 
            label="Criteria" 
            placeholder="Criteria" 
            wire:model="criteria" 
        />
        @error('criteria') <p class="text-red-500 text-sm">{{ $message }}</p> @enderror

        <flux:input 
            label="Marks" 
            type="number" 
            wire:model="marks"
        />
        @error('marks') <p class="text-red-500 text-sm">{{ $message }}</p> @enderror
        
        <div class="flex">
            <flux:spacer />
            
            <flux:button type="submit" wire:click="saveCriteria" variant="primary" color="sky">Add Criteria</flux:button> 
            </div>
    </div>
</flux:modal>

//Criterias.php "<?php

namespace App\Livewire\Admin;

use Livewire\Component; use App\Models\AssessmentCategory;

class Criterias extends Component {

public $criterias;

public function render()
{
    return view('livewire.admin.criterias');
}
public function mount(){
  $this->criterias=AssessmentCategory::all();
 
}


public $criteria;

public $marks;

public function saveCriteria()
{
   $validated=$this->validate([
     'criteria'=>'required|max:255',
     'marks'=>'required|max:2',        
    ]);
 
    AssessmentCategory::create($validated);
    $this->reset();


}



    
}

"

0 likes
10 replies
gotham337's avatar

Hey! 👋 Looks like your button’s wire:click="saveCriteria" is pointing to a function inside the Criterias component, but your modal is in criteria.blade.php — make sure that blade file is actually tied to the same Livewire component (App\Livewire\Admin\Criterias).

If it’s just a normal Blade view and not the Livewire component view, Livewire won’t detect the function. Try either:

Embedding your modal inside the component’s view (livewire/admin/criterias.blade.php), or

Wrapping your modal in <livewire:admin.criterias /> so Livewire can handle it.

Also, double-check that the component class name and Blade file name match (Criterias.php → criterias.blade.php).

1 like
bobvin042's avatar

Thanks for the reply. The blade file is actually tied to the same Livewire component ,, but i dont know why it does not call the function

Snapey's avatar

The name of the view is irrelevant.

I agree, check the browser console.

But actually, I would wrap your inputs in a form element and allow your submit button to actually submit the form.

bobvin042's avatar

Thank you for the reply but actually the class is named Criterias,, the file name is also named Criterias.php and the blade view file as criterias.blade.php,, it was just a typing error in above.. but still its not working

bobvin042's avatar

Browser console says: "Uncaught ReferenceError: $flux is not defined at [Alpine] $flux.appearance === 'system' && ! $flux.dark (eval at safeAsyncFunction (livewire.js?id=df3a17f2:1174:21), :3:32) at livewire.js?id=df3a17f2:1196:23 at tryCatch (livewire.js?id=df3a17f2:1116:14) at livewire.js?id=df3a17f2:3626:19 at reactiveEffect (livewire.js?id=df3a17f2:2432:18) at Object.effect2 [as effect] (livewire.js?id=df3a17f2:2407:7) at effect (livewire.js?id=df3a17f2:764:35) at wrappedEffect (livewire.js?id=df3a17f2:780:29) at Function. (livewire.js?id=df3a17f2:3626:5) at flushHandlers (livewire.js?id=df3a17f2:1281:48)"

Snapey's avatar

Is this modal inside a loop? How is it included in the parent page?

bobvin042's avatar

It is not in the loop

@include('partials.head')

    <!-- Table Container -->
    <div class="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
        <div class="overflow-x-auto">
            <table class="w-full">
                <thead class="bg-sky-600 text-white">
                    <tr>
                        <th class="px-6 py-4 text-left font-semibold text-sm uppercase tracking-wider">SNo</th>
                        <th class="px-6 py-4 text-left font-semibold text-sm uppercase tracking-wider">Assessment Criteria</th>
                        <th class="px-6 py-4 text-center font-semibold text-sm uppercase tracking-wider">Marks</th>
                        <th class="px-6 py-4 text-center font-semibold text-sm uppercase tracking-wider">Actions</th>
                    </tr>
                </thead>
                <tbody id="tableBody" class="divide-y divide-gray-200">
                    <!-- Sample Data -->
                    @foreach($criterias as $criteria)
                    <tr class="hover:bg-gray-50 transition-colors duration-150">
                        <td class="px-6 py-4 text-gray-700 font-medium">{{$criteria->id}}</td>
                        <td class="px-6 py-4 text-gray-700">
                            <div class="flex items-center gap-2">
                                <i class="fas fa-check-circle text-sky-500"></i>
                                <span>{{$criteria->criteria}}</span>
                            </div>
                        </td>
                        <td class="px-6 py-4 text-center">
                            <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-sky-100 text-sky-800">{{$criteria->marks}}</span>
                        </td>
                        <td class="px-6 py-4">
                            <div class="flex justify-center gap-2">
                                <button onclick="editRow(this)" class="text-sky-600 hover:text-sky-800 transition-colors p-2 hover:bg-sky-50 rounded-lg">
                                    <i class="fas fa-edit"></i>
                                </button>
                                <button onclick="deleteRow(this)" class="text-red-500 hover:text-red-700 transition-colors p-2 hover:bg-red-50 rounded-lg">
                                    <i class="fas fa-trash"></i>
                                </button>
                            </div>
                        </td>
                    </tr>
                    @endforeach
                  
                  
                </tbody>
                <tfoot class="bg-gray-50">
                    <tr>
                        <td colspan="2" class="px-6 py-4 font-semibold text-gray-700">Total Marks</td>
                        <td class="px-6 py-4 text-center">
                            <span id="totalMarks" class="inline-flex items-center px-3 py-1 rounded-full text-sm font-bold bg-sky-600 text-white">100</span>
                        </td>
                        <td></td>
                    </tr>
                </tfoot>
            </table>
        </div>
    </div>

    <!-- Statistics Cards -->
    <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mt-6">
        <div class="bg-white rounded-lg shadow-sm border border-gray-200 p-4">
            <div class="flex items-center justify-between">
                <div>
                    <p class="text-gray-600 text-sm">Total Criteria</p>
                    <p id="totalCriteria" class="text-2xl font-bold text-gray-800 mt-1">5</p>
                </div>
                <div class="bg-sky-100 p-3 rounded-lg">
                    <i class="fas fa-list-check text-sky-600 text-xl"></i>
                </div>
            </div>
        </div>
        <div class="bg-white rounded-lg shadow-sm border border-gray-200 p-4">
            <div class="flex items-center justify-between">
                <div>
                    <p class="text-gray-600 text-sm">Average Marks</p>
                    <p id="avgMarks" class="text-2xl font-bold text-gray-800 mt-1">20</p>
                </div>
                <div class="bg-sky-100 p-3 rounded-lg">
                    <i class="fas fa-chart-line text-sky-600 text-xl"></i>
                </div>
            </div>
        </div>
        <div class="bg-white rounded-lg shadow-sm border border-gray-200 p-4">
            <div class="flex items-center justify-between">
                <div>
                    <p class="text-gray-600 text-sm">Highest Mark</p>
                    <p id="highestMark" class="text-2xl font-bold text-gray-800 mt-1">30</p>
                </div>
                <div class="bg-sky-100 p-3 rounded-lg">
                    <i class="fas fa-trophy text-sky-600 text-xl"></i>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- Add Modal -->
        <flux:input 
            label="Criteria" 
            placeholder="Criteria" 
            wire:model="criteria" 
        />
        @error('criteria') <p class="text-red-500 text-sm">{{ $message }}</p> @enderror

        <flux:input 
            label="Marks" 
            type="number" 
            wire:model="marks"
        />
        @error('marks') <p class="text-red-500 text-sm">{{ $message }}</p> @enderror
        
        <div class="flex">
            <flux:spacer />
            
            <flux:button type="submit" wire:click="saveCriteria" variant="primary" color="sky">Add Criteria</flux:button> 
            </div>
    </div>
</flux:modal>

Please or to participate in this conversation.