Diego  Elizondo

Diego Elizondo

1659375000

Cómo Hacer Una URL De Paginación Bonita En Laravel

En este artículo, hablaremos sobre la URL bonita de paginación de Laravel. Este tutorial le dará un ejemplo simple de cómo hacer que la paginación sea una URL bonita en laravel. 

Puede usar este ejemplo con laravel 6, laravel 7, laravel 8 y laravel 9.

Laravel proporciona paginación predeterminada y funciona bien. Pero generan URL con cadenas de consulta y si necesita generar una URL bonita (URL compatible con SEO) para su paginación, entonces lo ayudaré con cómo puede hacerlo.

URL de paginación predeterminada de Laravel:

http://localhost:8000/users?page=1
http://localhost:8000/users?page=2
http://localhost:8000/users?page=3

Paginación de Laravel con bonita URL:

http://localhost:8000/users/page/1
http://localhost:8000/users/page/2
http://localhost:8000/users/page/3

Si desea generar una URL bonita, simplemente siga el paso a continuación para realizar este ejemplo:

Sigamos los pasos a continuación:

Paso 1: Instalar Laravel

Este paso no es obligatorio; sin embargo, si no ha creado la aplicación laravel, puede continuar y ejecutar el siguiente comando:

composer create-project laravel/laravel example-app

Paso 2: generar usuarios ficticios

En este paso, generaremos algunos usuarios ficticios para que podamos hacer la paginación, así que ejecutemos el comando Tinker y agreguemos nuevos usuarios:

php artisan tinker
User::factory()->count(40)->create()

Paso 3: Crear rutas

En este paso, crearemos dos rutas para usuarios y otra para URL bonitas. así que vamos a agregarlo.

rutas/web.php

<?php
  
use Illuminate\Support\Facades\Route;
  
use App\Http\Controllers\UserController;
   
/*
|--------------------------------------------------------------------------
| 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('users', [UserController::class, 'index']);
Route::get('users/page/{page}', [UserController::class, 'index'])->name('users.index');

Paso 4: Crear controlador

En este paso, tenemos que crear un nuevo controlador como UserController con index(). escribiremos lógica de paginación en él. así que actualicemos el siguiente código:

app/Http/Controllers/UserController.php

<?php
    
namespace App\Http\Controllers;
    
use Illuminate\Http\Request;
use App\Models\User;
    
class UserController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request, $page = 1)
    {
        $paginate = 4;
        $skip = ($page * $paginate) - $paginate;
        $prevURL = $nextURL = '';
  
        if ($skip > 0){
            $prevURL = $page - 1;
        }
  
        $users = User::latest()
                        ->skip($skip)
                        ->take($paginate)
                        ->get();
  
        if($users->count() > 0){
            if($users->count() >= $paginate){
                $nextURL = $page + 1;
            }

            return view('users', compact('users', 'prevURL', 'nextURL'));
        }
  
        return redirect('/');
    }
}

Paso 5: Crear archivo de vista

En el último paso, vamos a crear users.blade.php para crear un formulario con el mensaje de validación de visualización y colocar el siguiente código:

recursos/vistas/usuarios.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>Laravel Pagination Pretty URL Example - ItSolutionStuff.com</title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
        
<div class="container">
    <h1>Laravel Pagination Pretty URL Example - ItSolutionStuff.com</h1>
    
    <table class="table table-bordered data-table">
        <thead>
            <tr>
                <th>ID</th>
                <th>Name</th>
                <th>Email</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            @foreach($users as $user)
            <tr>
                <td>{{ $user->id }}</td>
                <td>{{ $user->name }}</td>
                <td>{{ $user->email }}</td>
                <td>
                    <a 
                        href="javascript:void(0)" 
                        id="show-user" 
                        class="btn btn-info"
                        >Show</a>
                </td>
            </tr>
            @endforeach
        </tbody>
    </table>
  
    <div class="text-center">
  
        @if($prevURL)
            <a class="btn btn-primary m-10 leftbtn" href="{{ route('users.index', $prevURL) }}"><i class="fa fa-angle-left" aria-hidden="true"></i> Previous</a>
        @endif
  
        @if($nextURL)
            <a class="btn btn-primary m-10 rightbtn" href="{{ route('users.index', $nextURL) }}">Next <i class="fa fa-angle-right" aria-hidden="true"></i> </a>
        @endif
  
    </div>
  
</div>
      
</body>
      
</html>

Ejecute la aplicación Laravel:

Se han realizado todos los pasos requeridos, ahora debe escribir el siguiente comando y presionar enter para ejecutar la aplicación Laravel:

php artisan serve

Ahora, vaya a su navegador web, escriba la URL dada y vea el resultado de la aplicación:

http://localhost:8000/users

Espero que te pueda ayudar...

 Fuente: https://www.itsolutionstuff.com/post/laravel-pagination-pretty-url-exampleexample.html

#laravel 

What is GEEK

Buddha Community

Cómo Hacer Una URL De Paginación Bonita En Laravel

How to Get Current URL in Laravel

In this small post we will see how to get current url in laravel, if you want to get current page url in laravel then we can use many method such type current(), full(), request(), url().

Here i will give you all example to get current page url in laravel, in this example i have used helper and function as well as so let’s start example of how to get current url id in laravel.

Read More : How to Get Current URL in Laravel

https://websolutionstuff.com/post/how-to-get-current-url-in-laravel


Read More : Laravel Signature Pad Example

https://websolutionstuff.com/post/laravel-signature-pad-example

#how to get current url in laravel #laravel get current url #get current page url in laravel #find current url in laravel #get full url in laravel #how to get current url id in laravel

Diego  Elizondo

Diego Elizondo

1659375000

Cómo Hacer Una URL De Paginación Bonita En Laravel

En este artículo, hablaremos sobre la URL bonita de paginación de Laravel. Este tutorial le dará un ejemplo simple de cómo hacer que la paginación sea una URL bonita en laravel. 

Puede usar este ejemplo con laravel 6, laravel 7, laravel 8 y laravel 9.

Laravel proporciona paginación predeterminada y funciona bien. Pero generan URL con cadenas de consulta y si necesita generar una URL bonita (URL compatible con SEO) para su paginación, entonces lo ayudaré con cómo puede hacerlo.

URL de paginación predeterminada de Laravel:

http://localhost:8000/users?page=1
http://localhost:8000/users?page=2
http://localhost:8000/users?page=3

Paginación de Laravel con bonita URL:

http://localhost:8000/users/page/1
http://localhost:8000/users/page/2
http://localhost:8000/users/page/3

Si desea generar una URL bonita, simplemente siga el paso a continuación para realizar este ejemplo:

Sigamos los pasos a continuación:

Paso 1: Instalar Laravel

Este paso no es obligatorio; sin embargo, si no ha creado la aplicación laravel, puede continuar y ejecutar el siguiente comando:

composer create-project laravel/laravel example-app

Paso 2: generar usuarios ficticios

En este paso, generaremos algunos usuarios ficticios para que podamos hacer la paginación, así que ejecutemos el comando Tinker y agreguemos nuevos usuarios:

php artisan tinker
User::factory()->count(40)->create()

Paso 3: Crear rutas

En este paso, crearemos dos rutas para usuarios y otra para URL bonitas. así que vamos a agregarlo.

rutas/web.php

<?php
  
use Illuminate\Support\Facades\Route;
  
use App\Http\Controllers\UserController;
   
/*
|--------------------------------------------------------------------------
| 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('users', [UserController::class, 'index']);
Route::get('users/page/{page}', [UserController::class, 'index'])->name('users.index');

Paso 4: Crear controlador

En este paso, tenemos que crear un nuevo controlador como UserController con index(). escribiremos lógica de paginación en él. así que actualicemos el siguiente código:

app/Http/Controllers/UserController.php

<?php
    
namespace App\Http\Controllers;
    
use Illuminate\Http\Request;
use App\Models\User;
    
class UserController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request, $page = 1)
    {
        $paginate = 4;
        $skip = ($page * $paginate) - $paginate;
        $prevURL = $nextURL = '';
  
        if ($skip > 0){
            $prevURL = $page - 1;
        }
  
        $users = User::latest()
                        ->skip($skip)
                        ->take($paginate)
                        ->get();
  
        if($users->count() > 0){
            if($users->count() >= $paginate){
                $nextURL = $page + 1;
            }

            return view('users', compact('users', 'prevURL', 'nextURL'));
        }
  
        return redirect('/');
    }
}

Paso 5: Crear archivo de vista

En el último paso, vamos a crear users.blade.php para crear un formulario con el mensaje de validación de visualización y colocar el siguiente código:

recursos/vistas/usuarios.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>Laravel Pagination Pretty URL Example - ItSolutionStuff.com</title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
        
<div class="container">
    <h1>Laravel Pagination Pretty URL Example - ItSolutionStuff.com</h1>
    
    <table class="table table-bordered data-table">
        <thead>
            <tr>
                <th>ID</th>
                <th>Name</th>
                <th>Email</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            @foreach($users as $user)
            <tr>
                <td>{{ $user->id }}</td>
                <td>{{ $user->name }}</td>
                <td>{{ $user->email }}</td>
                <td>
                    <a 
                        href="javascript:void(0)" 
                        id="show-user" 
                        class="btn btn-info"
                        >Show</a>
                </td>
            </tr>
            @endforeach
        </tbody>
    </table>
  
    <div class="text-center">
  
        @if($prevURL)
            <a class="btn btn-primary m-10 leftbtn" href="{{ route('users.index', $prevURL) }}"><i class="fa fa-angle-left" aria-hidden="true"></i> Previous</a>
        @endif
  
        @if($nextURL)
            <a class="btn btn-primary m-10 rightbtn" href="{{ route('users.index', $nextURL) }}">Next <i class="fa fa-angle-right" aria-hidden="true"></i> </a>
        @endif
  
    </div>
  
</div>
      
</body>
      
</html>

Ejecute la aplicación Laravel:

Se han realizado todos los pasos requeridos, ahora debe escribir el siguiente comando y presionar enter para ejecutar la aplicación Laravel:

php artisan serve

Ahora, vaya a su navegador web, escriba la URL dada y vea el resultado de la aplicación:

http://localhost:8000/users

Espero que te pueda ayudar...

 Fuente: https://www.itsolutionstuff.com/post/laravel-pagination-pretty-url-exampleexample.html

#laravel 

Seamus  Quitzon

Seamus Quitzon

1595201363

Php how to delete multiple rows through checkbox using ajax in laravel

First thing, we will need a table and i am creating products table for this example. So run the following query to create table.

CREATE TABLE `products` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
 `description` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
 `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
 `updated_at` datetime DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

Next, we will need to insert some dummy records in this table that will be deleted.

INSERT INTO `products` (`name`, `description`) VALUES

('Test product 1', 'Product description example1'),

('Test product 2', 'Product description example2'),

('Test product 3', 'Product description example3'),

('Test product 4', 'Product description example4'),

('Test product 5', 'Product description example5');

Now we are redy to create a model corresponding to this products table. Here we will create Product model. So let’s create a model file Product.php file under app directory and put the code below.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    protected $fillable = [
        'name','description'
    ];
}

Step 2: Create Route

Now, in this second step we will create some routes to handle the request for this example. So opeen routes/web.php file and copy the routes as given below.

routes/web.php

Route::get('product', 'ProductController@index');
Route::delete('product/{id}', ['as'=>'product.destroy','uses'=>'ProductController@destroy']);
Route::delete('delete-multiple-product', ['as'=>'product.multiple-delete','uses'=>'ProductController@deleteMultiple']);

#laravel #delete multiple rows in laravel using ajax #laravel ajax delete #laravel ajax multiple checkbox delete #laravel delete multiple rows #laravel delete records using ajax #laravel multiple checkbox delete rows #laravel multiple delete

Juned Ghanchi

1621508419

Laravel App Development Company in India, Hire Laravel Developers

Hire our expert team of Laravel app developers for flexible PHP applications across various cloud service providers.

With this easy build technology, we develop feature-rich apps that make your complex business process a lot easier. Our apps are,

  • More secure and scalable.
  • A good framework lets you manage and organize resources better.
  • And have a rich community base.

Get your business a best in classlaravel app. Hire laravel app developers in India. We have the best organizational set-up to provide you the most advanced app development services.

#laravel app development company india #hire laravel developers india #laravel app development company #hire laravel developers #laravel development agency #laravel app programmers

Liz  Fernandes

Liz Fernandes

1670234150

Best Laravel Development Company

In the present world, PHP is a well-liked framework. Laravel is one of the most well-known frameworks out there. The popularity of Laravel is due to its expressiveness, flexibility, good controllers, strength, seamless caching, and time savings when handling tasks like routing, authentication, sessions, and many more.

Laravel is a PHP framework that everyone who knows PHP should be familiar with. The Laravel PHP framework is simple to learn and use, but it is packed with useful features. Despite rising market competition, many developers consider Laravel to be one of the best PHP frameworks available.

WPWeb Infotech is a top Laravel development company in India and the US since 2015. They develop reliable, scalable Laravel web and mobile apps using Ajax-enabled widgets, MVC patterns, and built-in tools. WPWeb Infotech has top-notch expertise in combining a variety of front- and back-end technologies like Laravel + VueJS, Laravel + Angular, and Laravel + ReactJS to create scalable and secure web architectures, so you don't have to worry about scalability and flexibility while developing your product. They understand business scale and recommend technology that fits. Agile experts reduce web and mobile app development time and risk.

When it comes to hiring Laravel developers from India, they are the best choice because their Laravel developers can work according to your time zone to provide you with hassle-free, innovative, and straightforward web development solutions. Being the most trusted Laravel development company in India, they can help you reach new heights of success, unleashing the power of the Laravel PHP framework.

Partner with one of India’s best Laravel Development Company and get the most expertise in Laravel development.

#laravel  #laravel-development #laravel-development-company #laravel-development-services #hire-laravel-developers