I have this method where I pass some posts and also this "isAnyPostButtonChecked"
to the view:
public function edit($id)
{
...
$isAnyPostButtonChecked = false;
$isAnyPostButtonChecked = $isAnyPostButtonChecked && (old('radiobutton') && old('radiobutton') == $event->id);
return view('posts.edit')
->with('posts', $post)
->with('anyPost', $isAnyPostButtonChecked);
}
In the view I have a form and above the form I have "{{$anyPost}}"
to verify if any radio button is checked when the the form is submited. But it dont shows nothing with "{{$anyPost}}"
when a radio button is selected and the form is submited. Do you know why?
{{$anyPost}}
<form id="editposts" method="post"
action="{{route('posts.update', ['post_id' => $post->id])}}" enctype="multipart/form-data">
{{csrf_field()}}
<div>
@foreach($posts as $post)
<div class="form-check">
<input {{ (old('radiobutton') && old('radiobutton') == $post->id) ? 'checked' : '' }} class="form-check-input radio" type="radio" name="radiobutton" value="{{ $post->id }}" id="{{$post->id}}">
<label class="form-check-label">
{{$post->title}}
</label>
</div>
@endforeach
</div>
<div class="form-check">
<input checked checked {{ (old('radiobutton') && old('radiobutton') == 'create_post') ? 'checked' : '' }} class="form-check-input" type="radio" name="radiobutton" id="create_post"
value="create_post">
<label class="form-check-label">
Create post
</label>
</div>
<!-- form fields, here is the name but are more like description,... -->
<div class="form-group">
<label>Post title</label>
<input type="text" required class="form-control" value="{{ old('title') }}" name="title" id="tile">
</div>
<input type="submit" id="postupdate" value="Update"/>
</form>