print user role laravel Spatie - laravel

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.

Related

sum in blade how to do it for the subtotal of two tables?

i found out a way by someone asking a question, of a way of producing subtotals, i now just wanted to sum values between two tables , in the code from the person i tested and it works perfectly, i just wanted to aggregate more one table to any of the querys , it's summing on the blade.
//resumed controller
public function index() {
$emphayas = DB::select('select * from emphayas');
$treasuries = DB::select('select * from treasuries');
return view('database',['emphayas'=>$emphayas,
'treasuries'=>$treasuries,
]);}
-----------------------------------------------------------------
//resumed blade
<table class=" ">
<tr>
<th class="py-3 bg-cyan-400">Total</th>
<td class="py-3 bg-cyan-400">available_for_use_month</td>
</tr>
#foreach ($emphayas as $emphaya)
<tr>
<td></td>
<td>{{ $emphaya->available_for_use_month}}</td>
</tr>
#endforeach
<tr>
<td>Total</td>
<td>{{ \App\Models\Emphaya::sum('available_for_use_month') }}
</tr>
</table>
<table class=" ">
<tr>
<th class="py-3 bg-cyan-400">Total</th>
<td class="py-3 bg-cyan-400">available_for_use_month</td>
</tr>
#foreach ($treasuries as $treasury)
<tr>
<td></td>
<td>{{ $treasury->available_for_use_month}}</td>
</tr>
#endforeach
<tr>
<td>Total</td>
<td>{{ \App\Models\Treasury::sum('available_for_use_month') }}
</tr>
</table>
in this case what i want to do is connect the total of treasury to emphyas
<tr>
<td>Total</td>
<td>{{ \App\Models\Emphaya::sum('available_for_use_month') + \App\Models\Treasury::sum('available_for_use_month') }}
</tr>

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 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

Laravel 5 unable to render pagination

I'm new to Laravel 5 and I have an issue displaying pagination. I looked in the documentation and just can't get it to work.
usercontroller:
public function getIndex()
{
$users = User::where('active', '=','verified')->simplePaginate(10);
return View::make('User.index')->with('users',$users);
}
index.blade.php:
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>id</th>
<th>username</th>
<th>email</th>
<th>role</th>
<th>created</th>
<th class="actions">Actions</th>
</tr>
</thead>
<tbody>
#foreach($users as $user)
<tr>
<td>{{ $user->id }}</td>
<td>{{ $user->username }}</td>
<td>{{ $user->email }}</td>
<td>{{ $user->role }}</td>
<td>{{ $user->created_at }}</td>
<td class="actions">
blabla
</td>
</tr>
#endforeach
</tbody>
</table>
{!! $users->render() !!}
for some reason, it was printing an additional /
fix:
{!! str_replace('users/','users',$users->render()) !!}

Laravel: selecting multiple values with radio button

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.

Resources