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

Related tags

laravel-model-uuid
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
Issues
  • 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.

    good first issue help wanted 
    opened by mdcass 1
Owner
salman zafar
Software Engineer | Full Stack Developer | PHP | Laravel | Javscript | Python | Fast Api | React js | Vue Js
salman zafar
This package lets you add uuid as primary key in your laravel applications

laravel-model-uuid A Laravel package to add uuid to models Table of contents Installation Configuration Model Uuid Publishing files / configurations I

salman zafar 10 May 31, 2021
Please see the Diglactic fork.

Update: 18 October 2020 There is now an official fork of Laravel Breadcrumbs: https://github.com/diglactic/laravel-breadcrumbs Blog post: https://news

Dave James Miller 2.4k Jun 17, 2021
Sortable behaviour for Eloquent models

Sortable behaviour for Eloquent models This package provides a trait that adds sortable behaviour to an Eloquent model. The value of the order column

Spatie 947 Jun 11, 2021
Laravel Stats Tracker

Laravel Stats Tracker Tracker gathers a lot of information from your requests to identify and store: Sessions Page Views (hits on routes) Users (logge

Antonio Carlos Ribeiro 2.6k Jun 13, 2021
Inertia.js Events for Laravel Dusk

Inertia.js Events for Laravel Dusk Requirements PHP 7.4+ Vue Laravel 8.0 and higher Support We proudly support the community by developing Laravel pac

Protone Media 9 Jun 14, 2021
Automatically validating Eloquent models for Laravel

Validating, a validation trait for Laravel Validating is a trait for Laravel Eloquent models which ensures that models meet their validation criteria

Dwight Watson 918 Jun 8, 2021
Awes.io // boilerplate based on Vue, Nuxt, TailwindCSS plus Laravel as a backend. 🤟

Platform for Interactive Business Applications 10x faster to create than the traditional way • 3x increase application experiences • 60% decrease in d

Awes.io 640 Jun 15, 2021
A web installer for Laravel

Laravel Web Installer | A Web Installer Package About Requirements Installation Routes Usage Contributing Help Screenshots License About Do you want y

Rachid Laasri 1.7k Jun 13, 2021
Laravel Segment is an opinionated, approach to integrating Segment into your Laravel application.

Laravel Segment Laravel Segment is an opinionated, approach to integrating Segment into your Laravel application. Installation You can install the pac

Octohook 11 Apr 28, 2021
Laravel SEO - This is a simple and extensible package for improving SEO via meta tags, such as OpenGraph tags.

This is a simple and extensible package for improving SEO via meta tags, such as OpenGraph tags.

ARCHTECH 51 Jun 15, 2021
Easy creation of slugs for your Eloquent models in Laravel

Eloquent-Sluggable Easy creation of slugs for your Eloquent models in Laravel. NOTE: These instructions are for the latest version of Laravel. If you

Colin Viebrock 3.2k Jun 14, 2021
jQuery DataTables API for Laravel 4|5|6|7|8

jQuery DataTables API for Laravel 4|5|6|7|8 This package is created to handle server-side works of DataTables jQuery Plugin via AJAX option by using E

Arjay Angeles 3.9k Jun 14, 2021
A laravel Livewire Dynamic Selects with multiple selects depending on each other values, with infinite levels and totally configurable.

Livewire Combobox: A dynamic selects for Laravel Livewire A Laravel Livewire multiple selects depending on each other values, with infinite levels of

Damián Aguilar 15 Jun 5, 2021
Laravel blade directives and php helpers for serverside rendered content, based on browser window size WITHOUT css

Laravel Window Size and Breakpoints Laravel blade directives and php helpers for server side rendered content, based on browser window size WITHOUT cs

Tina Hammar 6 Jun 11, 2021