Laravel Splade "old input or default variable"?

504 views Asked by At

I am using the Laravel Splade package, I want old input when there is any validation error, and the page is refreshed; here is my input field.

<x-splade-form>
    {{-- Interact with the value of the data --}}
    <input type="text" v-model="form.name" />
    <p>Your name is: <span v-text="form.name" /></p>
 
    {{-- Toggle classes based on the value of the data --}}
    <input type="checkbox" v-model="form.newsletter" />
    <svg :class="{ 'text-green-500': form.newsletter, 'text-red-500': !form.newsletter }" />
 
    {{-- Show elements based on the value of the data --}}
    <input type="checkbox" v-model="form.agree_with_terms" />
    <button type="submit" v-show="form.agree_with_terms">Submit</button>
</x-splade-form>

I tried using remember function, but it didn't work.

<x-splade-form>
    {{-- Interact with the value of the data --}}
    <input old="name" type="text" v-model="form.name" />
    <p>Your name is: <span v-text="form.name" /></p>
</x-splade-form>
1

There are 1 answers

0
Kal-El On BEST ANSWER

Splade does it for you automatically:

All you need is:

<x-splade-form :default="$user" :action="route('users.update', $user)" method="PUT">

   <x-splade-input label="Name" name="name" />

   <x-splade-submit label="Save" />

</x-splade-form>

Splade will apply "old" to $user->name