I am using Laravel and I want to delete record from admin panel with button
so I want to use Ajax to does not refresh page when I want to delete
so problem is this
when I click on button the record is going to delete but the page does not show any change ( I mean the record is deleted but it's still in page and when I refresh the page It's going to hide and delete)
controller :
$comment = Comment::find($id);
$comment->delete($id);
view:
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">{{ __('comment.index.comments') }}</h1>
<div class="btn-toolbar mb-2 mb-md-0">
<div class="btn-group mr-2">
{{--{{ __('comment.index.create') }}--}}
{{--Export--}}
</div>
{{--<button class="btn btn-sm btn-outline-secondary dropdown-toggle">--}}
{{--<i class="fa fa-calendar-o"></i>--}}
{{--This week--}}
{{--</button>--}}
<span>
Excel <i class="fas fa-cloud-download-alt"></i>
Create <i class="fas fa-plus-square"></i>
</span>
</div>
</div>
<div class="table-responsive">
<table class="table table-striped table-sm">
<thead>
<tr>
<th>{{ __('comment.index.id') }}</th>
<th>{{ __('comment.index.user-id') }}</th>
<th>{{ __('comment.index.parent-id') }}</th>
<th>{{ __('comment.index.comment') }}</th>
<th>{{ __('comment.index.commentable-id') }}</th>
<th>{{ __('comment.index.commentable-type') }}</th>
<th>{{ __('comment.index.status') }}</th>
<th>{{ __('comment.index.data') }}</th>
<th>{{ __('comment.index.setting') }}</th>
</tr>
</thead>
<tbody>
#foreach($comments as $comment)
<tr>
<td>{{ $comment->id }}</td>
<td>{{ $comment->user_id }}</td>
<td>{{ $comment->parent_id }}</td>
<td>{{ $comment->comment }}</td>
<td>{{ $comment->commentable_id }}</td>
<td>{{ $comment->commentable_type }}</td>
<td>{{ $comment->status }}</td>
<td>{{ \Carbon\Carbon::parse($comment->created_at)->diffForHumans() }}</td>
<td>
{{--<form action="{{ route('change.approved', $comment->id) }}" method="post">--}}
{{--#csrf--}}
{{--{{ method_field('put') }}--}}
{{--<input value="change approved {{ $comment->approved }}" type="submit" class="btn btn-sm btn-success">--}}
{{--</form>--}}
{{--<form action="{{ route('comment.destroy', $comment->id) }}" method="post">--}}
{{--#csrf--}}
{{--{{ method_field('delete') }}--}}
{{--<input value="delete" type="submit" class="btn btn-sm btn-danger">--}}
{{--</form>--}}
<form class="form-inline" action="{{ route('change.approved', $comment->id) }}" method="post">
#csrf
{{ method_field('put') }}
{{--<input value="" >--}}
<button type="submit" class="btn btn-link"><i class="fa #if( $comment->approved == 1) fa-toggle-on text-success #else fa-toggle-off text-secondary #endif"></i> approved</button>
</form>
<hr class="p-0 m-1">
<button class="deleteProduct" data-id="{{ $comment->id }}" data-token="{{ csrf_token() }}" >Delete Task</button>
#csrf
{{ method_field('delete') }}
{{--<input value="delete">--}}
<button class="btn btn-sm btn-danger" type="submit"><i class="fa fa-trash"></i></button>
</form>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
<script>
$(".deleteProduct").click(function() {
var id = $(this).data("id");
var token = $(this).data("token");
$.ajax(
{
url: "comment/delete/"+id,
type: 'DELETE',
dataType: "JSON",
data: {
"id": id,
"_method": 'DELETE',
"_token": token,
},
success: function ()
{
console.log("it Work");
}
});
console.log("It failed");
});
</script>
and route :
Route::delete('/comment/delete/{id}', 'admin\CommentController#destroy')->name('comment.destroy');
By the way I use AJAX in my view
Add comment id in tr tag so that every tr tag will be unique. On success of ajax remove that row(tr) by using comment id.
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">{{ __('comment.index.comments') }}</h1>
<div class="btn-toolbar mb-2 mb-md-0">
<div class="btn-group mr-2">
{{--{{ __('comment.index.create') }}--}}
{{--Export--}}
</div>
{{--<button class="btn btn-sm btn-outline-secondary dropdown-toggle">--}}
{{--<i class="fa fa-calendar-o"></i>--}}
{{--This week--}}
{{--</button>--}}
<span>
Excel <i class="fas fa-cloud-download-alt"></i>
Create <i class="fas fa-plus-square"></i>
</span>
</div>
</div>
<div class="table-responsive">
<table class="table table-striped table-sm">
<thead>
<tr>
<th>{{ __('comment.index.id') }}</th>
<th>{{ __('comment.index.user-id') }}</th>
<th>{{ __('comment.index.parent-id') }}</th>
<th>{{ __('comment.index.comment') }}</th>
<th>{{ __('comment.index.commentable-id') }}</th>
<th>{{ __('comment.index.commentable-type') }}</th>
<th>{{ __('comment.index.status') }}</th>
<th>{{ __('comment.index.data') }}</th>
<th>{{ __('comment.index.setting') }}</th>
</tr>
</thead>
<tbody>
#foreach($comments as $comment)
<tr id="{{ $comment->id }}">
<td>{{ $comment->id }}</td>
<td>{{ $comment->user_id }}</td>
<td>{{ $comment->parent_id }}</td>
<td>{{ $comment->comment }}</td>
<td>{{ $comment->commentable_id }}</td>
<td>{{ $comment->commentable_type }}</td>
<td>{{ $comment->status }}</td>
<td>{{ \Carbon\Carbon::parse($comment->created_at)->diffForHumans() }}</td>
<td>
<form class="form-inline" action="{{ route('change.approved', $comment->id) }}" method="post">
#csrf
{{ method_field('put') }}
<button type="submit" class="btn btn-link"><i class="fa #if( $comment->approved == 1) fa-toggle-on text-success #else fa-toggle-off text-secondary #endif"></i> approved</button>
</form>
<hr class="p-0 m-1">
<button class="deleteProduct" data-id="{{ $comment->id }}" data-token="{{ csrf_token() }}" >Delete Task</button>
#csrf
{{ method_field('delete') }}
{{--<input value="delete">--}}
<button class="btn btn-sm btn-danger" type="submit"><i class="fa fa-trash"></i></button>
</form>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
<script>
$(".deleteProduct").click(function(){
var id = $(this).data("id");
var token = $(this).data("token");
$.ajax(
{
url: "comment/delete/"+id,
type: 'DELETE',
dataType: "JSON",
data: {
"id": id,
"_method": 'DELETE',
"_token": token,
},
success: function ()
{
console.log("it Work");
$("tr#"+id).remove();
}
});
console.log("It failed");
});
</script>
Just do it.
<script>
$(".deleteProduct").click(function(){
var btn = $(this);
var id = $(this).data("id");
var token = $(this).data("token");
$.ajax(
{
url: "comment/delete/"+id,
type: 'DELETE',
dataType: "JSON",
data: {
"id": id,
"_method": 'DELETE',
"_token": token,
},
success: function ()
{
btn.closest("tr").remove(); // closest tr removed
console.log("it Work");
}
});
console.log("It failed");
});
You just hide that row by click on it. some like that...
$(".deleteProduct").click(function(){
$(this).closest("tr").hide();
var id = $(this).data("id");
var token = $(this).data("token");
$.ajax(
{
url: "comment/delete/"+id,
type: 'DELETE',
dataType: "JSON",
data: {
"id": id,
"_method": 'DELETE',
"_token": token,
},
success: function ()
{
console.log("it Work");
}
});
console.log("It failed");
});
Hope this help..
You may use this in after success response
you have to modify your script
<script>
$(".deleteProduct").click(function(){
var id = $(this).data("id");
var token = $(this).data("token");
$.ajax(
{
url: "comment/delete/"+id,
type: 'DELETE',
dataType: "JSON",
data: {
"id": id,
"_method": 'DELETE',
"_token": token,
},
success: function ()
{
$(this).closest("tr").remove();
alret('record deleted success fully');//or whatever type alert you want to show
}
});
console.log("It failed");
});
Related
This is my first big project with Laravel. I added a multirow delete function for my users table, it worked and logged me off and I haven't been able to log in again. Also all my routes aren't working.
i'm not really certain on what to do, i've tried to log in with other user details but the result is still the same. I've created a new user profile too.
Below is the code on the user blade file
#extends('layouts.admin')
#section('content')
<!-- Page Heading -->
#can('user_create')
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h2 class="h3 mb-0 ">Staff</h2>
<span class="d-md-flex d-sm-block left-side ">
Add Staff
</span>
</div>
#endcan
<!-- toolbar -->
<div class="row">
<div class="col-2">
<div class="d-md-flex">
<span class="d-flex mr-4">
<span class="mr-2"><small>Sort</small></span> <div class="dropdown arrow">
<a class="dropdown-toggle font-weight-bold" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<small>All</small>
</a>
<div class="dropdown-menu dropdown-menu-right shadow animated--fade-in" aria-labelledby="dropdownMenuLink">
<a class="dropdown-item" href="#">Name</a>
<a class="dropdown-item" href="#">No of ticket</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
</span>
<span>
Layout off Staff
</span>
</div>
</div>
</div>
<div class="row">
<!-- main content column -->
<div class="col-xl-12 col-lg-12">
<div class="table-responsive px-1">
<table class="ajaxTable datatable datatable-User">
<thead>
<tr>
<th scope="col ml-3"><small class="align-middle">
<label class="checkbox-container">
<input type="checkbox" id="chkCheckAll">
<span class="checkmark"></span>
</label>
</th>
<th scope="col ml-3 "><small class="align-middle">Name <small></th>
<th scope="col ml-3"><small class="align-middle">Position<small></th>
<th scope="col ml-3"><small class="">Department<small></th>
<th scope="col ml-3"><small class="">Phone<small></th>
<th scope="col ml-3"><small class="">Email<small></th>
<th scope="col ml-3"><small class="">Assigned ticket<small></th>
<th scope="col ml-3"><small class="">Date Created<small></th>
<th scope="col ml-3"><small class="">Actions<small></th>
</tr>
</thead>
<tbody>
#foreach($users as $key => $user)
<tr class="rounded-3" id="sid{{ $user->id }}">
<td class="align-middle">
<label class="checkbox-container">
<input type="checkbox" name="ids" value="{{ $user->id }}" class="chkBoxClass" >
<span class="checkmark"></span>
</label>
</td>
<td>
<a href="{{ route("admin.users.show",$user) }}"><span class="d-block font-weight-bold">
<img class="img-profile rounded-circle mr-2" height ="40" width="40" src="https://source.unsplash.com/QAB-WJcbgJk/60x60">
{{ $user->name ?? '' }}</span></a>
</td>
<td>
#foreach($user->roles as $key => $item)
<span class="badge badge-info">{{ $item->title }}</span>
#endforeach
</td>
<td class="align-middle">
#foreach($user->categories as $key => $item)
<div>{{ $item->name }}</div>
#endforeach
</td>
<td class="align-middle">
{{ $user->phone}}
</td>
<td class="align-middle font-weight-bold">
{{ $user->email ?? '' }}
</td>
<td class="align-middle">
{{ count($user->tickets) }}
</td>
<td class="align-middle text-center">
{{ $user->created_at ?? '' }}
</td>
<td>
<div class="dropdown no-arrow">
<a class="dropdown-toggle font-weight-bold" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-ellipsis-v fa-sm fa-fw text-gray-400 "></i>
</a>
<div class="dropdown-menu dropdown-menu-right shadow animated--fade-in" aria-labelledby="dropdownMenuLink">
#can('user_show')
<a class="dropdown-item" href="{{ route('admin.users.show', $user->id) }}">
{{ trans('global.view') }}
</a>
#endcan
#can('user_edit')
<a class="dropdown-item" href="{{ route('admin.users.edit', $user->id) }}">
{{ trans('global.edit') }}
</a>
#endcan
#can('user_delete')
<form class="d-flex" action="{{ route('admin.users.destroy', $user->id) }}" method="POST" onsubmit="return confirm('{{ trans('global.areYouSure') }}');" style="display: inline-block;">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="submit" class="dropdown-item" value="{{ trans('global.delete') }}">
</form>
#endcan
</div>
</div>
</td>
</tr>
#endforeach
</tbody>
</table>
{{ $users->links() }}
</div>
</div>
</div>
#endsection
#section('scripts')
#parent
<script>
$(function ()
{
let dtButtons = $.extend(true, [], $.fn.dataTable.defaults.buttons)
#can('user_delete')
let deleteButtonTrans = '{{ trans('global.datatables.delete') }}'
let deleteButton = {
text: deleteButtonTrans,
url: "{{ route('admin.users.massDestroy') }}",
className: 'btn-danger',
action: function (e, dt, node, config) {
var ids = $.map(dt.rows({ selected: true }).nodes(), function (entry) {
return $(entry).data('entry-id')
});
if (ids.length === 0) {
alert('{{ trans('global.datatables.zero_selected') }}')
return
}
if (confirm('{{ trans('global.areYouSure') }}')) {
$.ajax({
headers: {'x-csrf-token': _token},
method: 'POST',
url: config.url,
data: { ids: ids, _method: 'DELETE' }})
.done(function () { location.reload() })
}
}
}
dtButtons.push(deleteButton)
#endcan
$.extend(true, $.fn.dataTable.defaults, {
order: [[ 1, 'desc' ]],
pageLength: 4,
});
$('.datatable-User:not(.ajaxTable)').DataTable({ buttons: dtButtons })
$('a[data-toggle="tab"]').on('shown.bs.tab', function(e){
$($.fn.dataTable.tables(true)).DataTable()
.columns.adjust();
});
})
</script>
<script>
$(function(e){
$("#chkCheckAll").click(function(){
$(".chkBoxClass").prop('checked', $(this).prop('checked'));
});
$('#DASR').click(function(e){
e.preventDefault();
var allids = [];
$("input:checkbox[name=ids]:checked").each(function(){
allids.push($(this).val());
});
$.ajax({
url:"{{route('admin.users.massDestroy')}}",
type:'DELETE',
data:{
ids:allids,
_token: $("input[name=_token]").val()
},
success:function(response)
{
$.each(allids,function(key, val){
$('#sid'+val).remove();
});
}
});
});
});
</script>
#endsection
Do you have a repo to share so we can see the full code base. I would say the problem is not to do with this page exactly. Would be interesting to know what the functionality is behind the route 'admin.users.massDestroy' too... this may have deleted something it should not have done.
Other than that I can only take a guess and possibly say the passwords aren't correct when logging in. Or something wrong with the cache. You could try clearing it.
Only the first row of the table is changing
HTML table
<tr>
<th scope="row">{{ $loop->iteration }}</th>
<td>{{ $entrepreneur->name }}</td>
<td>{{ $entrepreneur->contact }}</td>
<td>{{ $entrepreneur->address }}</td>
<td>{{ $entrepreneur->business_name }}</td>
<td>{{ $entrepreneur->business_address }}</td>
<td>
<div id="approval">
<button class="check-btn" id="check-btn-{{ $entrepreneur->id }}" data-toggle="modal" data-target="#checkModal-{{ $entrepreneur->id }}"><i class="fa fa-check"></i></button>
<button class="delete-btn" id="delete-btn-{{ $entrepreneur->id }}" data-toggle="modal" data-target="#rejectModal-{{ $entrepreneur->id }}"><i class="fa fa-close"></i></button>
</div>
</td>
</tr>
Ajax Function
$.ajax({
type: 'post',
url: "/changeAccepted/"+entrepreneur_id,
success: function(res) {
toastr["success"]('Entrepreneur accepted succesfully');
$('#checkModal-'+entrepreneur_id).modal('hide');
$('#approval').html('Accepted');
} });
I am trying to change the two buttons on 'id=approval', right now it is changing for only the first row. I also want to change for other rows when it is accepted.
Each html element on same page has to have unique id property.
As you are using table I think you have multiple rows and each row has its own buttons placed in <div id="approval"></div> element.
When you use $('#approval') selector, Jquery gets only first one.
If you want to select all and change every element you have to use any selector but id.
The simplest way is to use .class selector.
Example & Solution:
Html:
...
<div class="approval_class">
<button class="check-btn" id="check-btn-{{ $entrepreneur->id }}" data-toggle="modal" data-target="#checkModal-{{ $entrepreneur->id }}"><i class="fa fa-check"></i></button>
<button class="delete-btn" id="delete-btn-{{ $entrepreneur->id }}" data-toggle="modal" data-target="#rejectModal-{{ $entrepreneur->id }}"><i class="fa fa-close"></i></button>
</div>
...
Javascript (Jquery): (to change all rows as accepted)
$('.approval_class').html('Accepted');
Javascript (Jquery): (to change only that row which accepted)
$('#delete-btn-' + entrepreneur_id).closest('div').html('Accepted');
I have a view where some data is shown in a table with filtering option. When I choose an option of search from the filtering part I want only table part will be refreshed and shown the updated data. It means recent table data should clear new filtered data should show in table.
I have successfully filtered data from database using Ajax. But can't show the filtered data (Ajax response) in the table.
#extends('layouts.master')
#section('content')
{{--//--------------------------------------------------------------------------------------------------------}}
<div class="">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-lg-12 borrower_id">
<div class="pull-left">
<h2>Pending Loans</h2>
</div>
</div>
<div class="col-xs-3 col-sm-3 col-md-3 " >
<h6>Branch</h6>
<input class="form-control" type="text" placeholder="Branch Name" aria-label="Search" id="branch_selector" name="branch_selector" value="" >
</div>
<div class="col-xs-3 col-sm-3 col-md-3" >
<h6>Center</h6>
<input class="form-control" type="text" placeholder="Center Name" aria-label="Search" id="center_selector" name="center_selector" value="" >
</div>
<div class="col-xs-3 col-sm-3 col-md-3" >
<h6>Group</h6>
<input class="form-control" type="text" placeholder="Group Number" aria-label="Search" id="group_selector" name="group_selector" value="">
</div>
<div class="col-xs-3 col-sm-3 col-md-3" >
<h6>Search</h6>
<button type="submit"><i class="fa fa-search"></i></button>
</div>
</div>
</div>
</div>
</div>
{{-- #if ($message = Session::get('success'))
<div class="alert alert-success">
<p>{{ $message }}</p>
</div>
#endif --}}
<table class="table table-bordered" id="loan_table">
<tr>
<th>No</th>
<th>Borrower No</th>
<th>Loan Stage</th>
<th>Loan Amount</th>
<th>Release Date</th>
<th width="200px">Action</th>
</tr>
#foreach ($loans as $loan)
<tr>
<td>{{ ++$i }}</td>
<td>{{ $loan->borrower_no }}</td>
<td>{{ $loan->loan_stage }}</td>
<td>{{ $loan->loan_amount }}</td>
<td>{{ $loan->release_date }}</td>
<td width="100px">
<form action="{{ route('approving.destroy',$loan->borrower_no) }}" method="POST">
<a class="btn btn-info btn-sm" href="{{ route('approving.show',$loan->borrower_no) }}">Details of Borrower</a>
{{--<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" >Show</button>--}}
<a class="btn btn-success btn-sm" href="/approving/test/{{$loan->borrower_no}}">Approve</a>
#csrf
#method('DELETE')
<button type="submit" class="btn btn-danger btn-sm">Reject</button>
</form>
</td>
</tr>
#endforeach
</table>
{!! $loans->links() !!}
#section('scripts')
<script type="text/javascript">
$(document).ready(function () {
// var la = $(loans).val();
$(branch_selector).click(function(){
var branch = $(this).val();
console.log(branch)
$.ajax({
type: 'GET',
url: '{{ ('/bseclector') }}',
data: {'id':branch},
dataType: 'JSON',
success: function (data) {
console.log(data);
data.forEach(function(item){
console.log(item);
// $('#loan_table').append('$loans'+item);
})
}
});
});
$(center_selector).click(function () {
var center = $(this).val();
console.log(center);
$.ajax({
type: 'GET',
url: '{{ ('/cseclector') }}',
data: {'id':center},
dataType: 'JSON',
success: function (data) {
console.log(data);
}
});
});
$(group_selector).click(function () {
var group = $(this).val();
console.log(group);
$.ajax({
type: 'GET',
url: '{{ ('/gseclector') }}',
data: {'id':group},
dataType: 'JSON',
success: function (data) {
console.log(data);
;
data.forEach(function(item){
console.log(item);
// $('#loan_table').append('$loans'+item);
// $('#loan_table').append(${item+'$loans');
// $('#loan_table').append('<td>'+item.borrower_no+'</td>');
// $('#loan_table').append('<td>'+item.loan_stage+'</td>');
})
// });
}
});
});
});
</script>
#endsection
#endsection
I have an issue with "object not found by the #ParamConverter annotation" on Symfony 3.4 when I try to delete selected items of table. I think it's an issue when I try to get the "spectacle" with the id ("findOneBy()")
This is my code (html.twig) :
<form method="delete" action="{{ path('admin_spectacle_delete_selected') }}">
<button class="content-red btn btn-fabop" type="submit"><i class="fa fa-trash"></i> Tout supprimer</button>
<div class="table-responsive">
<table id="myTable" class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th style="text-align:center;"><input type="checkbox" id="all"></th>
<th>Nom</th>
<th>Lieu</th>
<th>Date spectacle</th>
<th>Annee</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for spectacle in spectacles %}
<tr>
<td id="spectacle{{ spectacle.id }}"><input type="checkbox" name='multiSelected[]' value="{{ spectacle.id }}"></td>
<td>{{ spectacle.nom }}</td>
<td>{{ spectacle.lieu }}</td>
<td>{{ spectacle.dateSpectacle }}</td>
<td>{{ spectacle.annee }}</td>
<td>
<a class="content-blue btn-fabop btn" href="{{ path('admin_spectacle_show', { 'id': spectacle.id }) }}"><i class="fa fa-search"></i> Détail</a>
<a class="content-purple btn-fabop btn" href="{{ path('admin_spectacle_edit', { 'id': spectacle.id }) }}"><i class="fa fa-pencil"></i> Edition</a>
<a class="content-red btn-fabop btn" href="{{ path('admin_spectacle_delete_confirmed', { 'id': spectacle.id }) }}"><i class="fa fa-trash"></i> Suppression</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
and controller :
/**
* Confirmation delete
*
* #Route("/deleteSelected", name="admin_spectacle_delete_selected")
*/
public function deleteSelectedAction(Request $request)
{
$items_selected_id = $request->get('multiSelected');
$em = $this->getDoctrine()->getManager();
$repository = $em->getRepository(Spectacle::class);
foreach($items_selected_id as $item_id) {
$spectacle = $repository->findOneById($item_id);
if (!$spectacle) {
throw $this->createNotFoundException(
'No spectacle found for id '.$spectacle
);
}
else{
$em->remove($spectacle);
}
}
$em->flush();
return $this->redirectToRoute('admin_spectacle_index');
}
Thank you for your response !!
Please try to change this:
<form method="delete"
to this:
<form method="post"
Because seems that you are get your variables like a POST action not a DELETE
In a list of user, I have an avatar. When I write this:
<img src="{{ $user->avatar }}" class="img-circle img-sm"/></a>
Scripts take 17 sec for 75 users.
But when I write:
<img src="{{ "/images/avatar/avatar.png" }}" class="img-circle img-sm"/></a>
it goes pretty quick.
Why is this attribute so time consuming???
In this page, I call a lot of attribute from this object, but only this one is time consuming... It's just string more....
I'm in Laravel 5.3
EDIT: Paste full table:
<table class="table datatable-responsive" id="table{{ $championship->id }}">
<thead>
<tr>
<th class="min-tablet text-center "
data-hide="phone">{{ trans('core.avatar') }}</th>
<th class="all">{{ trans('core.username') }}</th>
<th class="phone">{{ trans('core.email') }}</th>
<th align="center" class="phone">{{ trans_choice('categories.category',1) }}</th>
<th align="center" class="phone">{{ trans('core.paid') }}</th>
<th class="phone">{{ trans('core.country') }}</th>
#can('edit',$tournament)
<th class="all">{{ trans('core.action') }}</th>
#endcan
</tr>
</thead>
#foreach($championship->users as $user)
<?php
$arr_country = $countries->where('id', $user->country_id)->all();
$country = array_first($arr_country, null);
?>
<tr>
<td class="text-center">
{{--<a href="{!! URL::action('UserController#show', $user->slug) !!}"><img--}}
{{--src="{{ is_null($user->avatar) ? "/images/avatar/avatar.png" : $user->avatar }}" class="img-circle img-sm"/></a>--}}
</td>
<td>
#can('edit',$user)
{{ $user->name }}
#else
{{ $user->name }}
#endcan
</td>
<td>{{ $user->email }}</td>
<td class="text-center">{{ $championship->category->buildName($grades)}}</td>
<td class="text-center">
#if ($user->pivot->confirmed)
<?php $class = "glyphicon glyphicon-ok-sign text-success";?>
#else
<?php $class = "glyphicon glyphicon-remove-sign text-danger ";?>
#endif
#can('edit',$tournament)
{!! Form::open(['method' => 'PUT', 'id' => 'formConfirmTCU',
'action' => ['CompetitorController#confirmUser', $tournament->slug, $championship->id,$user->slug ]]) !!}
<button type="submit"
class="btn btn-flat btnConfirmTCU"
id="confirm_{!! $tournament->slug !!}_{!! $championship->id !!}_{!! $user->slug !!}"
data-tournament="{!! $tournament->slug !!}"
data-category="{!! $championship->id !!}"
data-user="{!! $user->slug !!}">
<i class="{!! $class !!} "></i>
</button>
{!! Form::close() !!}
#else
<i class="{!! $class !!} "></i>
#endcan
</td>
<td class="text-center"><img src="/images/flags/{{ $country->flag }}"
alt="{{ $country->name }}"/></td>
#can('edit',$tournament)
<td class="text-center">
{!! Form::model(null, ['method' => 'DELETE', 'id' => 'formDeleteTCU',
'action' => ['CompetitorController#deleteUser', $tournament->slug, $championship->id,$user->slug ]]) !!}
<button type="submit"
class="btn text-warning-600 btn-flat btnDeleteTCU"
id="delete_{!! $tournament->slug !!}_{!! $championship->id !!}_{!! $user->slug !!}"
data-tournament="{!! $tournament->slug !!}"
data-category="{!! $championship->id !!}"
data-user="{!! $user->slug !!}">
<i class="glyphicon glyphicon-remove"></i>
</button>
{!! Form::close() !!}
</td>
#endcan
</tr>
#endforeach
</table>
Is the avatar property a relationship to another table? It could be a lazy loading problem inside the foreach.
You can find more info about lazy and eager loading at Eloquent documentation.