PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 17, 2022

[FIXED] How to create unique indexes in Laravel?

 February 17, 2022     laravel, laravel-5, migration     No comments   

Issue

I create table with migration in laravel 5.6.

I need create a unique indexes with migration.

My code is:

$table->index([
            'system',
            'code',
            'city',
            'seat',
            'type'
        ], 'PrimaryPayment');

But after run migrate . in phpmyadmin -> table -> table_name -> indexes show unique: No

How to create unique indexes?


Solution

You can use unique() method on migration:

$table->string('email')->unique();

Or like this for compound unique index:

$table->unique([
        'system',
        'code',
        'city',
        'seat',
        'type'
    ], 'PrimaryPayment');


Answered By - Sohel0415
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing