PHP code example of jdavidbakr / ulidmodelroutes

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

    

jdavidbakr / ulidmodelroutes example snippets


use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

Schema::table('posts', function (Blueprint $table) {
    $table->ulid('ulid')->nullable()->unique();
});

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

Schema::table('posts', function (Blueprint $table) {
    $table->uuid('uuid')->nullable()->unique();
});

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use jdavidbakr\UlidModelRoutes\HasUlidRouteKey;

class Post extends Model
{
    use HasUlidRouteKey;
}

use App\Models\Post;
use Illuminate\Support\Facades\Route;

Route::get('/posts/{post}', function (Post $post) {
    return $post;
});

$post = Post::query()->first();

route('posts.show', $post);
// /posts/01K10R0X6T0B3R3D4Y8S0KQ7M4

class Team extends Model
{
    use HasUlidRouteKey;

    protected ?string $ulidRouteKeyColumnName = 'public_id';
}

return [
    'default_column_name' => 'public_id',
];

return [
    'id_type' => 'uuid', // 'ulid' or 'uuid'
    'uuid_type' => 'uuid7', // 'uuid7', 'uuid4', or 'ordered'
];
bash
php artisan vendor:publish --tag="ulidmodelroutes-config"
bash
php artisan ulidmodelroutes:backfill "App\\Models\\Post"