PHP code example of rossbearman / eloquent-calamari

1. Go to this page and download the library: Download rossbearman/eloquent-calamari 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/ */

    

rossbearman / eloquent-calamari example snippets


use RossBearman\Sqids\HasSqid;
use RossBearman\Sqids\SqidBasedRouting;

class Customer extends Model
{
    use HasSqid, SqidBasedRouting;
}

Route::get('/customer/{customer}', fn (Customer $customer) => $customer);

$customer = Customer::create(['name' => 'Squidward']);

$customer->id; // 1
$customer->sqid; // 3irWXI2rFV

Customer::findBySqid($sqid);

Customer::findBySqidOrFail($sqid);

Customer::whereSqid($sqid)->get();

Customer::whereSqidIn($sqids)->get();

Customer::whereSqidNotIn($sqids)->get();

class Customer extends Model
{
    use HasSqid, SqidBasedRouting;
    
    protected $appends = ['sqid'];
    protected $hidden = ['id'];
}

class Customer extends Model
{
    use HasSqid, SqidBasedRouting;
    
    public function getRouteKeyName(): string
    {
        return 'id';
    }
}

// Routes by ID by default
Route::get('/admin/customer/{customer}', fn (Customer $customer) => $customer);

// Routes by Sqid when specified
Route::get('/customer/{customer:sqid}', fn (Customer $customer) => $customer);

    'min_lengths' => [
        App\Model\Customer::class => 20,
        App\Model\Order::class => 8,
        App\Model\Invoice::class => 30,
    ],

    'canonical_checks' => [
        App\Model\Customer::class => false,
    ],
shell
php artisan vendor:publish --provider="RossBearman\Sqids\SqidsServiceProvider"
shell
php artisan sqids:alphabet "App\Models\Customer"
shell
php artisan sqids:check
shell
composer analyse