Laravel: selecting multiple values with radio button - laravel

I want to create a radio button field that will be selecting present, late, absent, others for each row of student.
The problem is... When i click the radio button for another student row... the radio button will pass down on the currently selected row and the one i selected previously will be gone.
Please Help.
Here's my view
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Student ID</th>
<th>Student Name</th>
<th>Present</th>
<th>Late</th>
<th>Absent</th>
<th>Others</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
#foreach ($users as $users)
<tr>
<td>{{ $users->student_id }} </td>
<td>{{ $users->student_firstname }} {{ $users->student_lastname }}</td>
<td>{{ Form::radio('result', 'present', true)}}</td>
<td> {{ Form::radio('result', 'late' ) }}</td>
<td>{{ Form::radio('result', 'absent') }}</td>
<td>{{ Form::radio('result', 'others') }}</td>
<td> <input id="comment" name="comment" type="text" class="form-control"></td>
#endforeach
</tr>

If all input fields have the exact same name of results its treated as one big input group with only one correct answer.
By appending the student id 'result['.$student->id.']' you are separating each row of input buttons into their own groups, allowing multiple radio button subgroups within a single <form>.
Which you can then catch the array of answers for each subgroup with Input::get('results') or $request->get('results') if your using Laravel's Form Request Validation.

Related

Please assist i want to loop through two database tables and view them in a blade.I want records to appear according to dates with in different column

All i want is to show debit and credit according to dates. I want debit to show only if there's new record added and also credit to show only if there's changes in the accounts. I have used observer to check if column is dirty.
here is my blade
<table class="table table-striped">
<thead style="background-color: #0b8a83;color:rgb(0, 0, 0);">
<th>Date</th>
<th>Description</th>
<th>Credit</th>
<th>Debit</th>
<th>Balance</th>
</thead>
#foreach ($monthlyInst as $keyy)
<tr>
<td>{{ date('d/M/y', strtotime($keyy->updated_at)) }}</td>
<td></td>
<td></td>
<td>R {{ $keyy->Installment }}</td>
<td></td>
</tr>
#endforeach
#foreach ($history as $account)
<tr>
<td>{{ date('d/M/y', strtotime($account->updated_at)) }}</td>
<td>{{ $account->accountname }}</td>
<td>R {{ $account->newpaid }}</td>
<td></td>
<td>R {{ $account->newbal }}</td>
</tr>
#endforeach
<tr>
<td></td>
<td>Outstanding Balance</td>
<td></td>
<td></td>
<td><b>R {{ $totalbal }}</b></td>
</tr>
</table>

How to concatenate a href in a go html template

I'd really appreciate if somebody could help me out with this. I've been going through similar questions asked but none seem to help with my problem.
I have a User table in a go template. In the right most column I have two buttons to update and delete a user. I want these buttons to point to a url that will update and delete that specific user. So I need to have the user id in the url.
This is the code:
<table class="table table-striped">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Date Of Birth</th>
<th>County</th>
<th>Books</th>
<th>Perform Action</th>
</tr>
</thead>
<tbody>
{{ range .Users}}
<tr>
<td>{{ .Id }}</td>
<td>{{ .Name }}</td>
<td>{{ .DateOfBirth }}</td>
<td>{{ .County }}</td>
<td>
{{if .Books}}
{{ range $id, $book := .Books }}
<li>{{ $book.Title }}</li>
{{ end }}
{{else}}
No Books
{{end}}
</td>
{{ $updateUrl := "http://localhost:8080/library/updateuser/" + .Id }}
<td>Update UserDelete User</td>
</tr>
{{ end}}
</tbody>
</table>
In the 5th line up from the bottom you'll see my incorrect attempt at concatenating the href with the id.
You cannot concatenate strings using +. This should work:
<a href="http://localhost:8080/library/deleteuser/{{ .Id }}">

print user role laravel Spatie

i'm filling a table with users information now I want to get his role too, i'm using Spatie/permission library
<thead>
<tr>
<th>Name</th>
<th>Last name</th>
<th>E-mail</th>
<th>Role</th>
<th>Status</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
#foreach (App\User::all() as $user)
<tr>
<td>{{ __($user->person->first_name)}}</td>
<td>{{ __($user->person->last_name) }}</td>
<td>{{ __($user->email) }}</td>
<td>{{ __() }}</td>
<td>{{ __($user->active) }}</td>
<td><button class="edit btn btn-sm btn-warning" value="{{ __($user->id)}}">Edit</button></td>
<td><button class="delete btn btn-sm btn-danger" value="{{ __($user->id)}}">Delete</button></td>
</tr>
#endforeach
</tbody>
I don't know if I have to create the relationship on User model or with the Spatie installation the relationships are ready to use
In order to get the name of the first role:
$user->roles->first()->name
Or you can get all of the roles separated by a comma:
$user->roles->implode(', ');
You can use like below if you need to show all roles assigned to user with comma seperated
$user->roles->pluck('name')->implode(',');
pluck() will return an array so we can use implode() with it.
Or
// get the names of the user's roles
$user->getRoleNames()->pluck('name')->implode(','); // getRoleNames() returns a collection
I hope this is useful.

Laravel+vuejs, how to loop inside table td tag?

Below shows my data. I am trying to loop Item inside table <td> tag so that it forms two items in one column.
user
>"name":"Bob"
>"id":1
>"Item":
>"name":"Desk"
>"name":"Chair"
Code
<table class="table table-hover">
<tbody>
<tr>
<th>Name</th>
<th>Items</th>
</tr>
<tr v-for="use in user.data" :key="use.id">
<td>{{ use.name }}</td>
<td v-for="a in use.item">
{{ a.name }},
</td>
</tr>
</tbody>
</table>
But when I do the codes above, it produce another column just like below picture. How do I put the Desk and Chair sits together in one column?
Hi just use a span tag in side td here is my solution, p or div tag are block tags, if you are using bootstrap 4 just set class to span inline-block or inline
<table class="table table-hover">
<tbody>
<tr>
<th>Name</th>
<th>Items</th>
</tr>
<tr v-for="use in user.data" :key="use.id">
<td>{{ use.name }}</td>
<td>
<span v-for="a in use.item"> {{ a.name }}, </span>
</td>
</tr>
</tbody>
</table>
v-for crates another elemenrs for you in each iteration. Use join function to display together
<tr v-for="use in user.data" :key="use.id">
<td>{{ use.name }}</td>
<td>
{{ use.item.join(", ") }},
</td>
</tr>
Output would be Desk, Chair
We can do this with using lodash
`
<tr v-for="use in user.data" :key="use.id">
<td>{{ use.name }}</td>
<td>
{{ _.map(use.item, 'name').join(", ") }}
</td>
</tr>
`

how to display laravel data in the form of text field values,

i am trying to display the laravel mmysql data in text field values, i am displaying upto table format, but i also need to update that value of the filed, like text filed values,
here is my code to display data in table format
<table border=1 align=center>
<thead>
<tr>
<td><h4>Name</h4></td>
<td><h4>Phoneno</h4></td>
<td><h4>Checkpost</h4></td>
<td><h4>Usertype</h4></td>
</tr>
</thead>
<tbody>
#foreach($profile as $user)
<tr>
<td>{{ $user->name }}</td>
<td>{{ $user->phoneno }}</td>
<td>{{ $user->checkpost }}</td>
<td>{{ $user->usertype }}</td>
</tr>
#endforeach
</tbody>
</table>
#endsection

Resources