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

onurzdgn's avatar

Submit form

Hello everyone, I am using Laravel 10 and Livewire 3. I am trying to submit form however I can' do. Can you help me because I can't find the problem? My tbody from blade:

@foreach ($daysInMonth as $day)
                    @if ($day['status'] == 0)
                        <tr>
                            <form wire:submit="saveAttendanceStatus">
                                @csrf
                                <td class="text-black">{{ $day['day'] }}</td>
                                <td>
                                    <select wire:model="attendanceStatus">
                                        <option value="">Seçiniz</option>
                                        <option value="1">Geldi</option>
                                        <option value="2">Yıllık İzin</option>
                                        <option value="3">İzinli</option>
                                        <option value="4">Hastalık (Raporlu)</option>
                                        <option value="5">Hastalık (Raporsuz)</option>
                                        <option value="6">Ücretli İzin</option>
                                        <option value="7">Yakın Vefatı</option>
                                        <option value="8">Evlilik</option>
                                        <option value="9">Doğum</option>
                                        <option value="10">Askerlik</option>
                                        <option value="11">Haber Vermeden Gelmedi</option>
                                        <option value="12">Diğer</option>
                                    </select>
                                </td>
                                <td>
                                    <button class="btn btn-primary">Kaydet</button>
                                </td>
                            </form>
                        </tr>
                    @elseif ($day['status'] == 1)
                        <tr>
                            <form wire:submit="updateAttendanceStatus">
                                @csrf
                                <td class="text-black">{{ $day['day'] }}</td>
                                <td>
                                    <select class="form-select" wire:model="attendanceStatus.{{ $day['day'] }}">
                                        <option value="">Seçiniz</option>
                                        <option value="1" @if ($day['reason'] == 1) selected @endif>Geldi</option>
                                        <option value="2" @if ($day['reason'] == 2) selected @endif>Yıllık İzin</option>
                                        <option value="3" @if ($day['reason'] == 3) selected @endif>İzinli</option>
                                        <option value="4" @if ($day['reason'] == 4) selected @endif>Hastalık (Raporlu)</option>
                                        <option value="5" @if ($day['reason'] == 5) selected @endif>Hastalık (Raporsuz)</option>
                                        <option value="6" @if ($day['reason'] == 6) selected @endif>Ücretli İzin</option>
                                        <option value="7" @if ($day['reason'] == 7) selected @endif>Yakın Vefatı</option>
                                        <option value="8" @if ($day['reason'] == 8) selected @endif>Evlilik</option>
                                        <option value="9" @if ($day['reason'] == 9) selected @endif>Doğum</option>
                                        <option value="10" @if ($day['reason'] == 10) selected @endif>Askerlik</option>
                                        <option value="11" @if ($day['reason'] == 11) selected @endif>Haber Vermeden Gelmedi</option>
                                        <option value="12" @if ($day['reason'] == 12) selected @endif>Diğer</option>
                                    </select>
                                </td>
                                <td>
                                    <button type="submit" class="btn btn-secondary">Güncelle</button>
                                </td>
                            </form>
                        </tr>
                    @else
                        <tr>
                            <td class="text-danger">HATA</td>
                            <td class="text-danger">HATA</td>
                            <td class="text-danger">HATA</td>
                        </tr>
                    @endif
                @endforeach

And this is my livewire controller:

<?php

namespace App\Livewire\Admin;

use App\Models\JobTracking;
use Carbon\Carbon;
use Livewire\Component;

class JobTrackingByWorker extends Component
{
    public $worker, $attendanceStatus;

    public function rules()
    {
        return [
            'worker' => ['required', 'numeric'],
            'attendanceStatus' => ['required', 'numeric'],
        ];
    }

    public function messages()
    {
        return [
            'worker.required' => 'Çalışan seçmelisiniz.',
            'worker.numeric' => 'Çalışan seçmelisiniz.',
            'attendanceStatus.required' => 'Durum seçmelisiniz.',
            'attendanceStatus.numeric' => 'Durum seçmelisiniz.',
        ];
    }

    public function render()
    {
        // Set start date of the month
        $startOfMonth = Carbon::now()->startOfMonth();

        // Take end date of the month
        $endOfMonth = Carbon::now()->endOfMonth();

        // Create an empty array to store the days of the month
        $daysInMonth = [];

        // Add days to the array, if the worker has a record for that day, add 1, if not, add 0
        $currentDate = $startOfMonth->copy();
        while ($currentDate->lte($endOfMonth)) {
            // Do the worker have a record for that day?
            $workerCalendar = JobTracking::where('day', $currentDate->toDateString())->where('worker_id', $this->worker)->first();

            // If the worker has a record for that day, set status to 1, if not, set status to 0
            $status = $workerCalendar ? 1 : 0;

            $daysInMonth[] = [
                'day' => $currentDate->toDateString(),
                'status' => $status,
                'reason' => $workerCalendar ? $workerCalendar->description->value : null,
            ];

            $currentDate->addDay();
        }

        return view('livewire.admin.job-tracking-by-worker', compact('daysInMonth'));
    }

    public function saveAttendanceStatus()
    {
        dd('saveAttendanceStatus');
        $this->validate();
    }
}
0 likes
11 replies
vincent15000's avatar

Do you have an error message ?

What doesn't work when you say that you can't submit the form ?

What I see in your form is that you don't have any worker field and you have a rule where you set the worker field as required.

So your form datas aren't validated given that you don't have any worker field.

onurzdgn's avatar

@vincent15000 I am waiting write screen "saveAttendanceStatus" because "dd". My url is this; http://127.0.0.1:8000/admin/jobTrackingByWorker/1, however no any error or warning just url changing to http://127.0.0.1:8000/admin/jobTrackingByWorker/1?_token=Zs6bzTAhWvQOoKU57IQI6GgN3iZ3gMoe5AANb6XE

1 like
vincent15000's avatar

@onurzdgn I don't understand.

What does dd('saveAttendanceStatus'); give ? Does it display saveAttendanceStatus on the screen ?

onurzdgn's avatar

@vincent15000 It show me ı hit the function.My form is not hit my function now. Or I understand like this

1 like
vincent15000's avatar

@onurzdgn

I really don't understand your responses.

Does it display saveAttendanceStatus on the screen ? => Yes or no ?

I can't use wire:submit.prevent => why ?

onurzdgn's avatar

@vincent15000 First question: No

Second question: I was used wire:submit.prevent but not work.

I want, my saveAttendanceStatus() function do something, I don't care what it do right now, just do it.

1 like
onurzdgn's avatar
onurzdgn
OP
Best Answer
Level 2

I found problem. I am using the DataTables, the problem is DataTables. I delete DataTables and work correctly.

1 like

Please or to participate in this conversation.