Search
 
SCRIPT & CODE EXAMPLE
 

PHP

uuid package generator laravel

//above in controller
use IlluminateSupportStr;

//in function
$uuid = Str::uuid()->toString();

//terminal
composer require "webpatser/laravel-uuid:^3.0"
Comment

uuid in laravel

use IlluminateSupportStr;

$uuid = Str::uuid()->toString();
Comment

uuid table laravel

$table->uuid('id');
Comment

uuid laravel

use IlluminateSupportStr;

$isUuid = Str::isUuid('a0a2a2d2-0b87-4a18-83f2-2529882be2de');

// true

$isUuid = Str::isUuid('laravel');

// false
Comment

UUIDs LARAVEL

//above in controller
use IlluminateSupportStr;

$uuid = (string) Str::uuid()
Comment

how to use uuid in laravel model

1) Implement Uuid trait.

// app/Traits/Uuid.php 
<?php

namespace AppTraits;

use Exception;
use IlluminateDatabaseEloquentModel;
use IlluminateSupportStr;

trait Uuid
{
    protected static function boot()
    {
        parent::boot();

        static::creating(function (Model $model) {
            try {
                $model->id = Str::uuid()->toString();
            } catch (Exception $e) {
                abort(500, $e->getMessage());
            }
        });
    }
}

2) Go to the model class and set $incrementing to false;

// app/Models/*.php
class Whatever implements Model {
	public $incrementing = false;
  	...
}

3) Go to the migration class and set uuid as primary key;
// database/migrations/*.php
class CreateWhateverTable extends Migration {
	public function up()
  	{
      Schema::create("whatever", function (Blueprint $table) {
          // You can change "id" to "uuid" or whatever...	  
          $table->uuid("id")->primary();
          // another column
      });
  	}
}
Comment

PREVIOUS NEXT
Code Example
Php :: how to send data from html to php 
Php :: laravel include config 
Php :: How to display custom field in wordpress? 
Php :: php wpdb foreach 
Php :: generate fake name php 
Php :: php include once inside a function? 
Php :: php variable as javascript function parameter in echo 
Php :: php get filename 
Php :: display pdf file in laravel 
Php :: php trim 
Php :: laravel where in 
Php :: laravel tinker insert db record 
Php :: jquery is less than or equal to 
Php :: how to create constant in php 
Php :: php apns notification source code 
Php :: php flatten array 
Php :: laravel import data from csv 
Php :: Get All dates of a month with laravel carbon 
Php :: laravel blade if else condition 
Php :: wp-config for production 
Php :: acos() php 
Php :: yii 2 create migration with fields 
Php :: laravel manually authenticate user 
Php :: php one line if without else 
Php :: resource route controller laravel 8 
Php :: foreach loop not working in php 
Php :: post format wordpress 
Php :: php refresh page without reloading 
Php :: php json_encode remove array index 
Php :: laravel seeder with relationships 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =