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

Jdubstep1357's avatar

Livewire - Entires into database are NULL

I was able to insert data into the database normally. However, when I tried to implement validation on the form, any and all new entries into the database are now NULL. What's strange is that the validation works, and there even is a success message if everything checks out. I do not understand why all the entries are null.

Here is my code:

// List of all variables in data

public $Date, $Visible_Public, $Start_8AM, $DHS_Certified, $In_Person, $IL_Class, $Instructor_First_Name, $Location_Name, $Max_Students, $Location_ID, $Course_Name, $Instructor, $Location;

public function store(Request $request) {

$validatedData = $this->validate([ 'Visible_Public' => 'required', 'Start_8AM' => 'required', 'DHS_Certified' => 'required', 'In_Person' => 'required', 'IL_Class' => 'required', 'Location_Name' => 'required', 'Max_Students' => 'required', 'Course_Name' => 'required', 'Date' => 'required', ]);

Class_Date_BitmappModel::create($request->only([
    'Visible_Public', 'Start_8AM', 'DHS_Certified', 'In_Person'
]));

Class_LocationModel::create($request->only([
    'Location_Name', 'Max_Students'
]));

Class_DateModel::create($request->only([
    'Date' => 'required'
]));

InstructorModel::create($request->only([
    'Instructor_First_Name'
]));

CourseModel::create($request->only([
    'Course_Name'
]));

session()->flash('message', 'Post made successfully');

 }

Here is an example of one of my input forms:

<div class="absolute right-25 md:w-2/3">    

    <input wire:model="Start_8AM" id="Start8" type="radio" value='true' class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">

    <label name="Start_8AM" for="Start_8AM">Yes</label>    

    <input wire:model="Start_8AM" id="Start8" type="radio" value='false' class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">

    <label for="Start_8AM">No</label>  
    @error('Start_8AM') <span class="text-red-600/100 error">{{ $message }}</span>@enderror
</div>
0 likes
6 replies
vincent15000's avatar

By Entires, do you mean Integers ? Which integers are null ? $Location_ID ?

Jdubstep1357's avatar

@vincent15000 Any form of data, whether a string, integer, or even binary data, is displayed as NULL in my database, upon a successful submission.

1 like
vincent15000's avatar

@Jdubstep1357 Oh all fields ?

After the validation, have you tried a dd($request->all()) or a dd($validatedData) ?

If you use the validation, you should then retrieve the data from the $validatedData variable to create each model, and not from the $request variable.

For example.

Class_LocationModel::create($validatedData->only([
    'Location_Name', 'Max_Students'
]));
Jdubstep1357's avatar

@vincent15000 Isn't the validation validated on a single request? And not multiple models? I had this issue the other day where I could only validate the FIRST group of data.

1 like
vincent15000's avatar
Level 63

@Jdubstep1357 Yes that's right, but first you validate all datas and then you create the models with the needed datas.

The $validatedData variable contains all the validated datas.

1 like
Jdubstep1357's avatar

@vincent15000 Thank you so much! That makes perfect sense now! I got confused with the global scope of variables versus the local scope.

1 like

Please or to participate in this conversation.