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

Soo's avatar
Level 2

old value checkbox

hello friends, i have form edit user .In this form i have checkbox to identify the old value role of user. i need to recover the old role of user . but it steel check the last role. this is the code of checkbox :

<div class="px-4 py-5 bg-white sm:p-6 ">
        <x-jet-label for="role_id" class="text-1xl"  value="{{ __('Roles :') }}" />
      @foreach($roles as $id => $role)
            <div><input type="radio" id="Role" name="role_id" value="{{ $role->id }}" checked >
            {{ $role->name }}</div>
          @endforeach
    </div>
0 likes
7 replies
webrobert's avatar

I'm not entirely sure what you're doing...

Did the user submit the form and it failed validation? Or are you wanting to show them what their role was and what it is now? Or ...

1 like
Soo's avatar
Level 2

@webrobert yes when i submit the form redirect me to the same interface. i need to edit the information of user(i use crud) but edit not work .i guest because the checkbox role .

webrobert's avatar

ahh, I think I understand. Can you show your code for updating?

Snapey's avatar
Snapey
Best Answer
Level 122

How you could use role in this case

<input type="radio" name="role_id" value="{{ $role->id }}" 
 if(old('role_id', $user->role_id) == $role->id) checked @endif>

but I have had to guess here. The second parameter of the old() helper is the default value, so is probably the user's role, but you will have to adapt this to suit whatever it is you are editing

1 like
Soo's avatar
Level 2

it work for me thank's for help. i put this line.

 <div><input type="radio" id="Role" name="role_id" value="{{ $role->id }}" @if($user->role_id==$role->id) checked @endif>
            {{ $role->name }}
</div>

Please or to participate in this conversation.