How to display laravel pagination numbers on top od the table - laravel

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>

Related

Get tags in view blade depending on how data is cycled

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>

Laravel 5.7 simple pagination

In our application, we have modules called Reports where in this report will show you the summarize of the module.
Example
General Journal Report - in this report will show you the summarize of the general journal module.
Now in our reports need to implement the pagination, having a problem applying the pagination in query builder.
Controller
$general_journals = GeneralJournalReportModel::getGeneralJournals();
$data['defined_gj'] = GeneralJournalReportItemsController::getDefinedGJById($general_journals);
I fetch all the general journal records and stored it in the variable general_journals then I passed it in another controller to do something else(such as putting some error handling when the column is null).
Model
public static function getGeneralJournals()
{
return DB::table('general_journals as gj')
->select('gj.id as id',
'gj.number as number',
'gj.posting_date as posting_date',
'gj.remarks as remarks',
'gj.document_reference as document_reference',
'gji.debit_amount as debit_amount',
'gji.credit_amount as credit_amount')
->leftJoin('general_journal_items as gji', 'gj.id', '=', 'gji.general_journal_id')
->where('gj.company_id', Auth::user()->company_id)
->where('gj.approval_status', 3)
->orderBy('gj.id', 'desc')
->simplePaginate(5);
}
View
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12 col-lg-12">
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover general-journal-report-table" id="gj-report">
<thead class="thead-global">
<tr>
<th id="pj_sequence">Sequence No.</th>
<th id="pj_date">Posting Date</th>
<th id="pj_op">Transaction No.</th>
<th id="4">Document Reference</th>
<th id="5">Remarks</th>
<th id="6">Amount Due</th>
</tr>
</thead>
<tbody class="general-journal-report-details">
#if($defined_gj)
<?php $counter = 0; ;?>
<?php $total_debit = 0; ?>
#foreach($defined_gj as $key => $value)
<?php $counter++;?>
<?php $total_debit += $value->debit ;?>
<tr>
<td class="pj_sequence">{{$counter}}</td>
<td class="pj_date">{{$value->posting_date}}</td>
<td class="pj_op">{!! $value->number !!}</td>
<td>{{$value->doc_ref}}</td>
<td>{{$value->remarks}}</td>
#if($value->debit == '0')
<td></td>
#else
<td align="right"> {{number_format($value->debit,2)}}</td>
#endif
</tr>
#endforeach
<tr>
<td><b>Total</b></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td align="right"> {{number_format($total_debit)}}</td>
</tr>
#endif
</tbody>
</table>
</div>
{{ $general_journals->links() }}
</div>
When I used the links() my button doesn't have any class.
Question: How do I put some class on the button of links?
NOTE: I tried this {{ $general_journals->links() }} but it only worked on the previous button(I want to also apply the class in the next button)
Try this
{{ $general_journals->links('pagination::bootstrap-4') }}
Replace with your laravel bootstrap version.
If you want to customize the pagination view, you can follow to this link https://laravel.com/docs/5.7/pagination#customizing-the-pagination-view

How do you create an increment of 1 in the Label Blade Template?

From the template of the blade a tag td foreach the I want to increase by one. How can I do that?
#foreach($winners as $winner)
<tr>
<td scope="row">
<span class="badge">1</span>
</td>
<td style="width:300px">
{{ $winner->name }}
</td>
<td></td>
<td style="width:50px">
{{ $winner->point }}
</td>
</tr>
#endforeach
Laravel's #foreach automatically has a variable called $loop
https://laravel.com/docs/5.8/blade#the-loop-variable
You can simply do:
<td scope="row"><span class="badge">{{ $loop->iteration }}</span></td>
Use php tags, apologies for formatting written on mobile
#php $i = 0; #endphp
#foreach($winners as $winner)
<tr>
<td scope="row">
<span class="badge">{{ $i }} </span>
</td>
<td style="width:300px">
{{ $winner->name }}
</td>
<td></td>
<td style="width:50px">
{{ $winner->point }}
</td>
</tr>
#php $i ++; #endphp
#endforeach
try this:
#php
$i=1;
#endphp
#foreach($winners as $winner)
<tr>
<td scope="row">
<span class="badge">{{ $i++ }}</span>
</td>
<td style="width:300px">
{{ $winner->name }}
</td>
<td></td>
<td style="width:50px">
{{ $winner->point }}
</td>
</tr>
#endforeach

pagination in laravel 5.3 when count of pages = 1

I have cities table and it has 7 cities I have a view page to display these cities with 10 cities per page
Controller:
$cities = City::orderBy('id', 'desc')->paginate(10);
return view('cities.home', compact('cities'));
View:
<div class="table-responsive panel panel-sky">
<table class="table table-striped table-hover">
<tr>
<th>#</th>
<th>Name</th>
<th>Created At</th>
<th>Action</th>
</tr>
#foreach($cities as $city)
<tr id="product{{$city->id}}">
<td>{{$city->id}}</td>
<td>{{$city->name}}</td>
<td>{{ $city->created_at }}</td>
<td>
<i class="glyphicon glyphicon-edit action-icon"></i>
<a type="button" class="pointer" data-toggle="modal" data-target="#deleteModal" data-type="btn-danger" data-action="delete-product" data-id="{{ $city->id }}" data-msg="Are you sure you want to delete this city?" data-title="Confirm Deletion">
<span class='glyphicon glyphicon-remove action-icon'></span>
</a>
</td>
</tr>
#endforeach
</table>
<div>
<div class="col-md-12"><?php echo $cities->render(); ?> </div>
but the issue is the paginate render is displayed with page#1, this issue occurred in laravel5.3 and did not find in laravel5.2
If you want to render pagination in your own way, you can use paginator methods. For example, to check if there is just one page, you could try:
#if ($cities->total() > 10)
// Render pagination
#endif

Laravel 5.2 pagination: how to decrease distance from table

I have a Laravel 5.2 application. I'm using the default Laravel pagination. All works functionally but there is quite some empty space between the last row of the table and the pagination link. See picture for an example:
How can I make the empty space a bit less?
Here is the code I'm using:
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th class="hidden-xs">Auction id</th>
<th>Name</th>
<th>Description</th>
<th><em class="fa fa-cog"></em>Actions</th>
</tr>
</thead>
<tbody>
#foreach( $events as $event )
<tr>
<td align="center" class="hidden-xs">{{ $auction->id }}</td>
<td>{{ $event>name }}</td>
<td>{{ $event->description }}</td>
<td align="center">
<div>
<em class="fa fa-list-alt"></em>
</div>
</tr>
#endforeach
</tbody>
</table>
<div class="text-right">
{{ $events->render() }}
</div>
<div class="text-right">
<!-- Your pagination code here -->
</div>

Resources