PHP code example of swiss-devjoy / laravel-easy-hashids
1. Go to this page and download the library: Download swiss-devjoy/laravel-easy-hashids library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
swiss-devjoy / laravel-easy-hashids example snippets
use SwissDevjoy\LaravelEasyHashids\HasHashid;
use SwissDevjoy\LaravelEasyHashids\HashidRouting;
class Product extends Model
{
use HasHashid;
use HashidRouting;
}
$product = Product::find(1);
echo $product->hashid; // Returns something like "2tFub5I1ge"
Route::get('/products/{product}', function (Product $product) {
return view('products.show', compact('product'));
})->name('products.product');
// Generates a URL with the hashid that looks sth like /products/2tFub5I1ge
route('products.show', ['product' => $product]);