I have the code shown below.
Cycle the clinics; for each response, if the clinic id corresponds to the clinic id present in the response and if the guest id corresponds to the guest id present in the response I want it to print the date of the response otherwise the button to add the response.
As I did, the code prints me how many buttons (even if the date is present) how many responses, while as I said above, I want to get the button only if the date is not present.
<table id="tabledata" class="table table-striped hover">
<thead>
<tr>
<th>Surname</th>
<th>Name</th>
<th>Phone</th>
#foreach($clinics as $clinic)
<th>{{$clinic->name}}</th>
#endforeach
</tr>
</thead>
<tbody>
#foreach ($guests as $guest)
<tr>
<td>{{ $guest->surname }}</td>
<td>{{ $guest->name }}</td>
<td> {{ $guest->phone }}</td>
#foreach($clinics as $clinic)
<td>
#foreach($guest_responses as $guest_response)
#if(($guest->id == $guest_response->guest_id) && ($clinic->id == $guest_response->clinic_id))
<p>{{$guest_response->date}}</p>
#endif
<button type="button" class="btn btn-success buttonclinic" data-bs-toggle="modal" data-bs-target="#responseModal" data-id-clinic="{{$clinic->id}}" data-id-guest="{{$guest->id}}" data-name-clinic="{{$clinic->name}}" data-surname-guest="{{ $guest->surname }}" data-name-guest="{{ $guest->name }}"><i class="fa-regular fa-plus"></i></button>
#endforeach
</td>
#endforeach
</tr>
#endforeach
</tbody>
</table>
Can anyone help me?
How about to add a flag to check a response with a date?
<td>
#php
$exist_response_date = false;
#endphp
#foreach($guest_responses as $guest_response)
#if(($guest->id == $guest_response->guest_id) && ($clinic->id == $guest_response->clinic_id))
#php
if($guest_response->date) {
$exist_response_date = true;
}
#endphp
<p>{{$guest_response->date}}</p>
#endif
#endforeach
#if(!$exist_response_date)
<button type="button" class="btn btn-success buttonclinic" data-bs-toggle="modal" data-bs-target="#responseModal" data-id-clinic="{{$clinic->id}}" data-id-guest="{{$guest->id}}" data-name-clinic="{{$clinic->name}}" data-surname-guest="{{ $guest->surname }}" data-name-guest="{{ $guest->name }}"><i class="fa-regular fa-plus"></i></button>
#endif
</td>
I have 2 modals (Modal1 & Modal2), in table after clicked on action button "edit" base on data, i need to open any one modal.
Say if age is less than 36 months then Modal 1 Else Modal 2 should open. Both modals have few data common and few are added newly.
This is my table code
<table id="cowcalfsummery" class="table table-bordered table-hover table" style="width:100%">
<thead>
<tr>
<th>ID</th>
<th>Breed Type</th>
<th>Gender</th>
<th>Birth Date</th>
<th>Weight (Kg)</th>
<th>Age (in Months)</th>
<th>Maturity Date</th>
<th>Health Status</th>
<th>Action</th>
</tr>
<tbody>
#foreach ($cowcalfdata as $item )
<tr id="item{{$item->id}}">
<td>{{$item->calfID}}</td>
<td>{{$item->breedtype}}</td>
<td>{{$item->gendertype}}</td>
<td>{{ date('d-m-Y', strtotime ($item->birthdate) ) }}</td>
<td>{{$item->weight}}</td>
<td>{{$item->age}}</td>
<td>{{ date('d-m-Y', strtotime ($item->maturitydate) ) }}</td>
<td>{{$item->health}}</td>
<td>
<i class="fas fa-eye" title="View"></i>
**<button type="button"** class="editcowcalfmodal btn btn-success" data-info="{{$item->id}},{{$item->calfID}},{{$item->birthdate}},{{$item->age}},{{$item->breedtype}},{{$item->gendertype}},{{$item->health}},{{$item->status}},{{$item->color}},{{$item->weight}},{{$item->height}},{{$item->previousvaccinedone}},{{$item->maturitydate}}" data-toggle="modal" data-target="#editcowcalfmodal"><i class="far fa-edit" title="Edit"></i></button>
<button type="button" class="btn btn-danger deletecowcalfdatabtn" data-cowcalfid="{{$item->calfID}}"><i class="fas fa-trash" title="Delete"></i></button>
</td>
</tr>
#endforeach
</tbody>
</thead>
</table>
Thanks in Advance.
You want to create a blade If statement and check if $item->age is below 36.
if it is you want to show the first button, else show the second button with a different data-target to your second modal.
#if($item->age < 36)
<button type="button"
class="editcowcalfmodal btn btn-success"
data-info="
{{$item->id}},
{{$item->calfID}},
{{$item->birthdate}},
{{$item->age}},
{{$item->breedtype}},
{{$item->gendertype}},
{{$item->health}},
{{$item->status}},
{{$item->color}},
{{$item->weight}},
{{$item->height}},
{{$item->previousvaccinedone}},
{{$item->maturitydate}}"
data-toggle="modal"
data-target="#editcowcalfmodal">
<i class="far fa-edit" title="Edit"></i>
</button>
#else
<button type="button"
class="editcowcalfmodal btn btn-success"
data-info="
{{$item->id}},
{{$item->calfID}},
{{$item->birthdate}},
{{$item->age}},
{{$item->breedtype}},
{{$item->gendertype}},
{{$item->health}},
{{$item->status}},
{{$item->color}},
{{$item->weight}},
{{$item->height}},
{{$item->previousvaccinedone}},
{{$item->maturitydate}}"
data-toggle="modal"
data-target="#MySecondModal">
<i class="far fa-edit" title="Edit"></i>
</button>
#endif
You also have your table wrong.
You first want to create a <thead> (table header). fill it with table titles, close the <thead> and after that you create the <tbody> (table body) with the content of the item.
This should create a structure like this:
<table>
<thead>
<tr>
<th>Age</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>12</td>
<td>Cow 1</td>
</tr>
</tbody>
</table>
More information about tables and how to use them
I would like to know how to put a list of the last 5 items in the dashboard using backpack?
I made the table
<div class="table-responsive">
<table class="table table-hover m-0 table-actions-bar">
<thead>
<tr>
<th>
<div class="btn-group dropdown">
<button type="button" class="btn btn-light btn-xs dropdown-toggle waves-effect waves-light"
data-toggle="dropdown" aria-expanded="false"><i class="mdi mdi-chevron-down"></i></button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Dropdown link</a>
<a class="dropdown-item" href="#">Dropdown link</a>
</div>
</div>
</th>
<th>Titolo Post</th>
<th>Data</th>
<th>Stato</th>
<th>Categria</th>
<th>Azione</th>
</tr>
</thead>
<tbody>
<tr>
<td>
</td>
<td>
<h5 class="m-0 font-weight-medium"></h5>
</td>
<td>
<i class="mdi mdi-map-marker text-primary"></i>
</td>
<td>
<i class="mdi mdi-clock-outline text-success"></i>
</td>
<td>
<i class="mdi mdi-currency-usd text-warning"></i>
</td>
<td>
<i class="mdi mdi-pencil"></i>
<i class="mdi mdi-close"></i>
</td>
</tr>
</tbody>
</table>
</div>
I made the table inside the jumbotron.blade.php then the function that prints you on screen the last 5 posts I put it here? within the dashboard method?
$recentPost : Article::orderBy('id', 'desc')>limit(5)->get()
any other solution?
This line will get you the last 5 articles.
$articles = Article::orderBy('id', 'desc')->limit(5)->get();
You need to pass it to the view. Ex:
return view('dashboard', ['articles' => $articles]);
And loop the articles on the blade file table. Ex:
<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Title</th>
<th scope="col">Author</th>
<th scope="col">Date</th>
</tr>
</thead>
<tbody>
#foreach($articles as $article)
<tr>
<th scope="row">{{ $article->id }}</th>
<td>{{ $article->title }}</td>
<td>{{ $article->author }}</td>
<td>{{ $article->created_at }}</td>
</tr>
#endforeach
</tbody>
</table>
I am using Laravel pagination from controller to paginate some list of data in a table. The pagination numbers are only displaying on the bottom of the table. How do i get to display the numbers on the top of the table as well?
my view:
<table>
<thead>
<tr>
<th>Make</th>
<th>Model</th>
</tr>
</thead>
<tbody>
#foreach ($cars as $car)
<tr>
<td>{{$car->make}}</td>
<td>{{$car->model}}</td>
</tr>
#endforeach
</tbody>
</table>
<div class="pull-right">
{{ $cars->links() }}
</div>
If you copy {{ $cars->links() }} at the top, it will also show you the same pagination like button. It looks like the following
<div class="pull-right">
{{ $cars->links() }}
</div>
<table>
<thead>
<tr>
<th>Make</th>
<th>Model</th>
</tr>
</thead>
<tbody>
#foreach ($cars as $car)
<tr>
<td>{{$car->make}}</td>
<td>{{$car->model}}</td>
</tr>
#endforeach
</tbody>
</table>
<div class="pull-right">
{{ $cars->links() }}
</div>
$cars->links() generates pagination button/links.
You can move it to wherever you like:
<div class="pull-right">
{{ $cars->links() }}
</div>
<table>
<thead>
<tr>
<th>Make</th>
<th>Model</th>
</tr>
</thead>
<tbody>
#foreach ($cars as $car)
<tr>
<td>{{$car->make}}</td>
<td>{{$car->model}}</td>
</tr>
#endforeach
</tbody>
</table>
use this on the top as well
<div class="pull-right">
{{ $cars->links() }}
</div>
I'm really new to MVC hope you can give me a detailed instructions on this.
I have a query in my repository that returns pending users who have a certain role_id. Now my issue is this I when the administrator clicks on the anchor tag of id idMessenger below
<li> Messenger<span class="label label-danger pull-right">{{$messenger->count()}}</span> </li>
I want to show the pending messengers only in the
<div class="col-md-2 left-aside">
<div class="scrollable">
<ul class="inbox-nav capitalize-font">
<li>All Pending Applications </li>
<li>Clients<span class="label label-danger pull-right">{{$elderly->count()}}</span></li>
<li> Messenger<span class="label label-danger pull-right">{{$messenger->count()}}</span> </li>
</ul>
</div>
</div>
<!-- /.left-aside-column-->
<div class="col-md-10 right-aside">
<div class="scrollable">
<div class="table-responsive">
<table id="datable_1" class="table display table-hover contact-list" data-page-size="10">
<thead>
<tr>
<th>Appication ID</th>
<th>Name</th>
<th>Email</th>
<th>Senior Citizen Number</th>
<th>Role/Submitted as</th>
<th>Date of Submission</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
#foreach($allPending as $user)
<tr>
<td>{{$user->id}}</td>
<td>{{$user->name}}</td>
<td>{{$user->email}}</td>
<td>{{$user->scn}}</td>
<td><span class="label label-danger">{{$user->roles->name}}</span></td>
<td>{{$user->created_at}}</td>
<td>
<i class="fa fa-check"></i>Approve
</td>
<td>
<i class="fa fa-trash"></i>Delete
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
Can you please teach me how to do it in ajax.