@catalyph
The problem - as you found is, that when come back to the page from the controller with errors on the session, it will not be loaded into livewire because that is not how livewire works. Livewire works by small ajax requests in the background where information is injected.
A controller works by loading the page from scratch. It's a brand new fresh load of the page. Your livewire component will also be fresh. The validation data is stored on the session. Your livewire component is completely encapsulated. You could get the data in there. But it would be a lot of painful work.
If you were using livewire for the form, all of this work is done for you. Everytime you make a change to one of the variables in your livewire component, you're sending data back to the server in an ajax request. Submitting forms is pretty much what Livewire was built for.
It's still the same work that you do in the controller, just slightly differently. You still define your validation with exactly the same rules you would use in a controller, and perform the same action. But you wire up your submit form action to a submit method in your livewire component. Your wire up the components that store the data to public properties on the livewire class. These You define a rules method and define your validation there. In the submit method you call $this->validate instead of validating the request. It returns the errors if there are any.
Something like this:
(please excuse the comments if they're stating stuff you already know)
livewire/create-time.blade.php (I've taken out all the formatting for clarity)
<form wire:submit="submit"> <!-- This connects the submit action of the form to the submit method in the component -->
<x-formfield label="Start Date" name="start_time" type="date" wire:model="start_time" required></x-formfield><!-- The wire:model connects the $start_time variable to the value of this component -->
<!-- Whatever else you have your livewire component do -->
<button type="submit">Submit</button>
@error('start_time')
<p>{{ $message }}</p>
@enderror
</form>
CreateTime.php
<?php
namespace App\Livewire\Forms;
use Livewire\Form;
class CreateTime extends Form
{
public $start_time = '';
public function rules()
{
return [
'start_time' =>['required','date_format:Y-m-d']
];
}
public function submit()
{
$this->validate(); // This uses your validation rules to validate the public properties
// Do action for saving here. Redirect to where you need to go, just like from a controller.
}
public function render()
{
return view('livewire.create-time');
}
}
This is all shown in https://livewire.laravel.com/docs/forms
You'll find the docs say you could also define your rules in an Attribute. I just prefer the rules method (mentioned further down).
Blade is great if you just have a simple form that doesn't do anything interesting while you're filling it in. As soon as you want to make it interesting, you end up needing some sort of front end framework like Livewire or Inertia/Vue, etc. It's worth learning how to use them properly.