This package lets you add uuid as primary key in your laravel applications

Overview

laravel-model-uuid

A Laravel package to add uuid to models

Table of contents

Installation

composer require salmanzafar/laravel-model-uuid

Configuration (optional)

Publishing service provider

php artisan vendor:publish --provider="Salman\LaravelModelUUID\LaravelModelUUISServiceProvider::class"

Enable the package (Optional)

This package implements Laravel auto-discovery feature. After you install it the package provider and facade are added automatically for laravel >= 5.5.

Model Uuid

There are many cases where we want to use uuid as primray key in our model now that is also easier you can use uuid as pk in a jiffy

namespace App;

use \Vault\LaravelVaultUUID\Concerns\UsesUuid;
use Illuminate\Database\Eloquent\Model;

class Car extends Model
{
   use UsesUuid;
}

By just using UsesUuid in your model now you have uuid as pk in your model. don't forget to make changes in migration

<?php

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

class CreateCarsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('cars', function (Blueprint $table) {
            $table->uuid('id')->primary();            
            $table->string('name');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

Publishing files

The below command will publish all related files inside App\Concerns folder

php artisan publish:uuid-trait
You might also like...
Generate UUID for a Laravel Eloquent model attribute

Generate a UUIDv4 for the primary key or any other attribute on an Eloquent model.

A simple laravel package to handle multiple key based model route binding

Laravel Model UUID A simple package to handle the multiple key/column based route model binding for laravel package Installation Require the package u

A Laravel package to retrieve key management from AWS Secrets Manager

A Laravel package to retrieve key management from AWS Secrets Manager Communication via AWS Secrets Manager may incur unnecessary charges. So we devel

⚙️Simple key/value typed settings for your Laravel app with synchronized json export

Simple key/value typed settings for your Laravel app Create, store and use key/value settings, typed from numbers over dates to array, cached for quic

This Laravel Nova tool lets you run artisan and bash commands directly from Nova 4 or higher.
This Laravel Nova tool lets you run artisan and bash commands directly from Nova 4 or higher.

Laravel Nova tool for running Artisan & Shell commands. This Nova tool lets you run artisan and bash commands directly from nova. This is an extended

Use eloquent joins in Laravel way, with composite key support.

Eloquent Power Joins with Compoships Support This package is an Eloquent Power Joins extension to support Compoships. You can now use joins in Laravel

⚙️Laravel Nova Resource for a simple key/value typed setting

Laravel Nova Resource for a simple key/value typed setting Administer your Laravel Simple Setting in Nova Pre-requisites This Nova resource package re

A Laravel package helps you add a complete real-time messaging system to your new / existing application with only one command.
A Laravel package helps you add a complete real-time messaging system to your new / existing application with only one command.

A Laravel package helps you add a complete real-time messaging system to your new / existing application with only one command.

This package helps you to add user based follow system to your model.

Laravel Follow User follow unfollow system for Laravel. Related projects: Like: overtrue/laravel-like Favorite: overtrue/laravel-favorite Subscribe: o

Comments
  • Using Event:fake() in tests prevents UUID creation

    Using Event:fake() in tests prevents UUID creation

    In a test, you'd expect the following to work (L8)

    Event::fake(); $user = User::factory()->create([ 'email_verified_at' => null, ]);

    However fails due to the required event not firing. Hacky solution is to implement this in tests which would prevent your package being added to a more established project due to the requirement of refactoring tests (stops you package being as "drop in" as you'd like).

    Looks like using dedicated Event classes may be a solution (altering the definition of the vent on the model) but I didn't have time to validate. At the very least this should be mentioned in the documentation.

    help wanted good first issue 
    opened by mdcass 1
Owner
salman zafar
Software Engineer | Full Stack Developer | PHP | Laravel | Javscript | Python | Fast Api | React js | Vue Js
salman zafar
Laravel package to generate and to validate a UUID according to the RFC 4122 standard. Only support for version 1, 3, 4 and 5 UUID are built-in.

Laravel Uuid Laravel package to generate and to validate a universally unique identifier (UUID) according to the RFC 4122 standard. Support for versio

Christoph Kempen 1.7k Dec 28, 2022
cybercog 996 Dec 28, 2022
Stop duplicating your Eloquent query scopes and constraints in PHP. This package lets you re-use your query scopes and constraints by adding them as a subquery.

Laravel Eloquent Scope as Select Stop duplicating your Eloquent query scopes and constraints in PHP. This package lets you re-use your query scopes an

Protone Media 75 Dec 7, 2022
The package lets you generate TypeScript interfaces from your Laravel models.

Laravel TypeScript The package lets you generate TypeScript interfaces from your Laravel models. Introduction Say you have a model which has several p

Boris Lepikhin 296 Dec 24, 2022
🏭This package lets you create factory classes for your Laravel project.

Laravel Factories Reloaded ?? This package generates class-based model factories, which you can use instead of the ones provided by Laravel. Laravel 8

Christoph Rumpel 372 Dec 27, 2022
A laravel package to attach uuid to model classes

Laravel Model UUID A simple package to generate model uuid for laravel models Installation Require the package using composer: composer require touhid

null 10 Jan 20, 2022
This package provides a trait that will generate a unique uuid when saving any Eloquent model.

Generate slugs when saving Eloquent models This package provides a trait that will generate a unique uuid when saving any Eloquent model. $model = new

Abdul Kudus 2 Oct 14, 2021
Use auto generated UUID slugs to identify and retrieve your Eloquent models.

Laravel Eloquent UUID slug Summary About Features Requirements Installation Examples Compatibility table Alternatives Tests About By default, when get

Khalyomede 25 Dec 14, 2022
A simple drop-in solution for providing UUID support for the IDs of your Eloquent models.

Introduction A simple drop-in solution for providing UUID support for the IDs of your Eloquent models. Both v1 and v4 IDs are supported out of the box

GoldSpec Digital 501 Jan 4, 2023
Laravel Larex lets you translate your whole Laravel application from a single CSV file.

Laravel Larex Translate Laravel Apps from a CSV File Laravel Larex lets you translate your whole Laravel application from a single CSV file. You can i

Luca Patera 68 Dec 12, 2022