0

I am trying to develop a page in which available appointments are listed. So the students will be able to choose one for foreign language talking exercise. Everything is fine. I get

Undefined variable $showConfirmationModal

error at line @if ($showConfirmationModal) .

I checked the variable names many times. This is because something else I guess. I also made a "find and replace" for $showConfirmationModal. I get the same error message.

I used the artisan commands:

php artisan cache:clear
php artisan view:clear

No help.

<?php

use App\Mail\AppointmentNotificationForStudent;
use App\Mail\AppointmentNotificationForTeacher;
use App\Models\TeacherAvailability;
use Carbon\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Mail;
use Livewire\Component;
use Masmerise\Toaster\Toaster;

new class extends Component {
    public $showConfirmationModal = false;
    public $selectedAppointmentId = null;
    public $appointments = [];

    public function mount()
    {
        $this->loadAppointments();
    }

    public function loadAppointments()
    {
        $this->appointments = TeacherAvailability::where('date', '>=', now()->toDateString())
            ->orderBy('date', 'ASC')
            ->orderBy('time_start', 'ASC')
            ->get();
    }

    public function confirmSelectAppointment($appointmentId)
    {
        $this->selectedAppointmentId = $appointmentId;
        $this->showConfirmationModal = true;
    }

    public function selectAppointment()
    {
        $studentId = Auth::id();
        $availability = TeacherAvailability::find($this->selectedAppointmentId);

        if (!$availability) {
            Toaster::error('Appointment not found.');
            return;
        }
 
        $availability->update([
            'student_id'      => $studentId,
            'is_appointment'  => 0,
        ]);

        Toaster::success('Randevu başarıyla seçildi!');
        $this->showConfirmationModal = false;

        $student = Auth::user();
  
        $teacher = $availability->teacher;  
        $teacherEmail = $teacher->email;
        $teacherName  = $teacher->name;

        Mail::to($teacherEmail)->queue(new AppointmentNotificationForTeacher($availability, $teacherEmail, $student, $teacherName));
        Toaster::success('Notification sent to the teacher.');

        
        Mail::to($student->email)->queue(new AppointmentNotificationForStudent($availability, $student));
        Toaster::success('Appointment information sent you in an e-mail.');

        // Populate List
        $this->loadAppointments();
    }
};
?>
<div>
    <!-- I get error at the line below-->
    @if ($showConfirmationModal) 
        <div class="fixed inset-0 bg-black bg-opacity-50 flex justify-center items-center z-50">
            ...
        </div>
    @endif

    <!-- Appointment List -->
    <div>
       ...
       ...
    </div>
</div>
3
  • $showConfirmationModal is not a variable. It's a property of class Component. Commented Feb 9 at 21:31
  • @KIKOSoftware so? Fine, they are property. However Laravel says "Undefined variable $showConfirmationModal". Commented Feb 9 at 21:41
  • 1
    The error simply means the variable doesn't exist, which is true. To get the property you first need to instantiate an object of class Component, like so: $myComponent = new Component();. Then you might want to use one of its methods before you access the property like so: if ($myComponent->showConfirmationModal) Commented Feb 9 at 22:06

1 Answer 1

0

Finally I noticed that I have called the wrong "Component" Class.

use Livewire\Component;

should be

use Livewire\Volt\Component;

Now, everything is fine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.