Laravel 7.2 routing with route group auth guard check with prefixLaravel 7.2 routing with route group auth guard check with prefix

Hello to all, welcome to therichpost.com. In this post, I will tell you, How to encrypt laravel id in URL? Like I always say that laravel is the best Mvc php framework.

Sometimes, we need to send id in url but this is not safe, if we will send direct id in url like( user/1, user/2 ) so, today we will use hashids in url to make it secure:

Very First, you need Require hashids package, with Composer you can install this, in the root directory of your project and below is command and you need to run this into your command prompt:

$ composer require hashids/hashids

 After this, you can use this with following code:

//in Controllers

use Hashids\Hashids;

$hashids = new Hashids();
echo $hashids->encode(1); //NA4ByeBWQp

//or

$id = $hashids->encode(1, 2, 3); // o2fXhV
$numbers = $hashids->decode($id); // [1, 2, 3]

//Route Bindings

$id = $hashids->encode(1);

//html
<a href="user<?php echo $id ; ?>">user</a>

 if you have any query related this post then please do ask.

 

By therichpost

Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

2 thoughts on “How to encrypt laravel id in URL?”
  1. Simply use in href tag in blade template file:

    {!! Hashids::encode($client->objectId); !!}

    In controller file:
    $client_id = \Hashids::decode($request->client_id);

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.