PHP code example of sirmathays / prefixed-id

1. Go to this page and download the library: Download sirmathays/prefixed-id 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/ */

    

sirmathays / prefixed-id example snippets


use App\Models\Human;

$human = Human::pidFindOrFail("H-1");
$human->pid; // Prints "H-1"
$human->id; // Prints 1

use Illuminate\Support\Facades\Route;

Route::get('humans/{human}', [HumanController::class, 'show']);

public function show(Request $request, Human $human)
{
    // 
}

use Illuminate\Support\Facades\Route;

Route::get('resources/{prefixedModel}', [ResourceController::class, 'show']);

public function show(Request $request, Model $model)
{
    //
}

use SirMathays\PrefixedId\Facades\PrefixedId;

$human = PrefixedId::findModel('H-1');
$dog = PrefixedId::findModel('D-1');
bash
php artisan vendor:publish --provider="SirMathays\PrefixedId\PrefixedIdServiceProvider"