Hi, artisan
In this article, I will share with you how to use laravel pagination in your laravel application. i know this is not big task for more exp. developers in laravel. but this is only for a newcomer. so I will share here step by step.
First, we need to create one fresh laravel application help of running the following artisan
command in the terminal.
composer create-project laravel/laravel firstApp --prefer-dist
Now, we need to create one route for getting the data from the user's table and then listing the data with pagination. first, you should add some dummy data in the users
table.
Route::get('get-users', '[email protected]')->name('get-users');
Now, we need to create UserController.php
files help of the following artisan command.
php artisan make:controller UserController
Now write the following code in app/Http/Controllers/UserController.php
file.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
class UserController extends Controller
{
/**
* Show the users listing
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function getUser()
{
$data = User::paginate(10);
return view('users', compact('data'));
}
}
Into the last, we need to create blade file in resources/views/users.blade.php
file and simply write the following layout code into it.
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Users Data</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Fonts -->
<link rel="dns-prefetch" href="//fonts.gstatic.com">
<link href="//fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
<!-- Styles -->
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
@foreach($data as $key => $value)
<tr>
<td>{{ $value->id }}</td>
<td>{{ $value->name }}</td>
<td>{{ $value->email }}</td>
</tr>
@endforeach
</tbody>
</table>
{{ $data->links() }}
</div>
</body>
</html>
i hope it can be help you.
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Failed to listen on 127.0.0.1:8000 (reason: Address already in use)
Laravel is the most popular and open-sou...Login with Twitter in Angular9 using Firebase
I am going to show you how you can ...Disable Text Selection In WebPage Using jQuery and CSS
Many times you need to prevent text sele...Laravel 8 - Livewire Load More On Page Scroll Step by Step
in this article, you'll learn how to...What is manifest.json file and how it is useful
The manifest.json is a simple JSON file...