Hello artisan in this brand new tutorial i am going to discuss about load more data on button click using jquery in Laravel using ajax request. You know that when we want to devide our posts then pagination is needed to do that.
We can use many kinds of pagination to devide our posts. But in this example i will show you load more data with button click in Laravel application. I will use ajax to send client request and will use axios to send get request.
So if you don't know how we can create load more dynamic in laravel 8 functionalities then this laravel load more example tutorial is for you. So let's start load more data on page scroll in laravel tutorial.
Step 1: Download Laravel
We are going to start from scratch. So download a fresh Laravel application to create load more in Laravel.
composer create-project laravel/laravel blog
Step 2: Create Model
In this step we have to create model to create database. As we are going to create load more in Laravel so we need table. So let's create it by the following command.
php artisan make:model Product -m
Now add those field and create migration.
database/migrations
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->text('text');
$table->float('price')->default(50);
$table->timestamps();
});
}
Now update your product model with the following piece of code.
app\Models\Product.php
protected $fillable = ['name','text','price'];
Step 3: Create Route
Now in this step we have to create two route to create our load more system in Laravel application. So create route like that:
routes/web.php
Route::get('load-data',[LoadMoreDataController::class,'index']);
Route::post('load-data', [LoadMoreDataController::class, 'loadMoreData'])->name('load-data');
Now open controller and paste this code:
app/Http/Controllers/LoadMoreDataController.php
Step 4: Create View
We are almost done. In this step we have to create our view to see the data and load more button. So let' create it
Read also: Laravel 8.x Infinite Scroll (Load More) Example Tutorial
Hope it can help you.
#laravel #laravel-8x #load-more #infinite-scroll #ajax #axios