<?php
use App\Http\Controllers\HomeController;
use Illuminate\Support\Facades\Route;
/*
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', [HomeController::class, 'tags'])->name('tags');
Route::get('/test', [HomeController::class, 'tags'])->name('tags');
// Auth::routes();
Route::get('/home', [HomeController::class, 'index'])->name('home');
<?php
namespace App\Http\Controllers;
use DB;
class HomeController extends Controller {
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct() {
// $this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index() {
return view('home');
}
public function tags() {
$tags = DB::table('tags')->paginate(7);
return view('tags', compact('tags'));
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateTagsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up() {
Schema::create('tags', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down() {
Schema::dropIfExists('tags');
}
}
<?php
namespace Database\Factories;
use App\Models\Tag;
use Illuminate\Database\Eloquent\Factories\Factory;
class TagFactory extends Factory {
protected $model = Tag::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition() {
return [
'name' => $this->faker->text(10),
];
}
}
C:\xampp\htdocs\reset\app\Models\Tag.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Tag extends Model {
use HasFactory;
}
Laravel 5.3 - Customize pagination templates example from scratch
By Hardik Savani October 10, 2016 Category : LaravelPauseUnmuteLoaded: 4.23%FullscreenToday, I am going to tell you how to building and apply new custom paginator view in Laravel 5.3. Laravel 5.3 added new features and update for easily implement your own manual pagination blade template.
By Default Laravel 5.3 provide us very simple bootstrap pagination view. But if you are not using bootstrap and you want to change then you can simply change OR if you want to add new bootstrap pagination layout then you can do it.
In bellow example you can see how to create custom blade layout and use them. This example from scratch so you can simply implement it in your project or laravel 5.3 application. So, you can also see bellow preview of example pagination.
Preview:
Laravel 5.3 added some new things on pagination view files. Laravel 5.3 give us to simply change on existing default pagination layout also so, you can run bellow command and it will create some files for pagination view.
After bellow command run you will get new folder "pagination" on views files(resources/views/vendor). In pagination folder you will get following files by default:
1)default.blade.php
2)bootstrap-4.blade.php
3)simple-bootstrap-4.blade.php
4)simple-default.blade.php
You can also use bellow blade template for pagination and also change on this files.
Step 1: Create New Table with Data
In first step, we are going to create new our own custom layout file from scratch so first we have to create new one table will some records.
In this example i created new table "tags" and with some
dummy data as like bellow screen shot.
tags table
Step 2: Add New Route
Ok, after created table and dummy data, we have to add new route for example so add bellow new "tags" route in web.php file.
Ok, now we have to add new controller method "tags()" in your HomeController, so if you haven't created HomeController then you can create by following command put bellow code:
command for create controller
php artisan make:controller HomeController
app/Http/Controllers/HomeController.php
<?phpnamespace App\Http\Controllers;use Illuminate\Http\Request;use App\Http\Requests;use DB;class HomeController extends Controller{ public function tags() { $tags = DB::table('tags')->paginate(7); return view('tags',compact('tags')); }}
Step 4: Create Blade File For Pagination
Ok, now we have to create new custom.blade.php file for our custom pagination template. In this file changed bootstrap class and also add new text for next and previous so it seems different layout for pagination layout.
so first i going to create blade file and put bellow code: