Questions tagged [laravel-schema-builder]

21 questions
13
votes
5 answers

Best way to store and load JSON from database in Laravel

I'm trying to store json into a db and load it back I tried to store {name: "John", age: 31, city: "New York"} It stored correctly. I checked the db, it showed correctly. {name: "John", age: 31, city: "New York"} I kept getting on the…
code-8
  • 54,650
  • 106
  • 352
  • 604
7
votes
6 answers

How to set auto increment into non primary key?

How would I set a database auto increment field that is not a primary key on the creation method? The only way is using a raw query? DB::statement('ALTER TABLE table CHANGE field field INT(10)AUTO_INCREMENT');
Luiz
  • 2,429
  • 8
  • 28
  • 43
6
votes
0 answers

Laravel Schema Builder partial indexes

How can I create partial indexes using Laravel 5.2's Schema Builder? For instance, instead of the query create index alternate_listing_not_null on listings(alternate_listings_id) where alternate_listings_id is not null how would I do this with…
eComEvo
  • 11,669
  • 26
  • 89
  • 145
5
votes
1 answer

Updating the data of an existing column and copying data with migrations

Is it possible to add a new column, copy some data to this new column and update the data in another column with a Laravel migration? I have a table something like this; id item price 1 ItemOne 100.00 2 ItemTwo 200.00 Now what I need…
5
votes
1 answer

Can I use Laravel's Schema::createDatabase() without first selecting a DB?

I have a little bit of a chicken and egg problem here. I am building a multitenant app in Laravel where each tenant has their own database on a Postgrsql server. So I have a job to create a new tenant that…
4
votes
1 answer

Add varchar column type with SQL Server using Laravel

I'm using Laravel 5.7 along with SQL Server 2017 and I want to generate a varchar(50) column called name. Executing this code gives me a nvarchar(50) instead: Schema::create('test', function(Blueprint $table) { $table->string('name',…
3
votes
1 answer

Laravel 5.3 Schema::create ENUM field is VARCHAR

I just created fresh migration. After running it I see my field type not ENUM type. It has a VARCHAR(255) type instead Schema::create('payments', function (Blueprint $table) { $table->increments('id'); $table->text('response'); …
alvery
  • 1,863
  • 2
  • 15
  • 35
2
votes
2 answers

How to optimize query statement in Laravel 7?

I show code in the screenshot, because I want to show you guys my line 43 The actual code is here : public function index() { $inputs = Request::all(); $interval = ''; if(array_key_exists('interval', $inputs)){ $interval …
code-8
  • 54,650
  • 106
  • 352
  • 604
2
votes
1 answer

Laravel Schema Builder not setting the right digits amount on Double datatype

So, I need to save amounts that go up to 999,999,999,999.99, and in the documentation of the Schema Builder of Laravel says that I can set up up to 15 digits and 8 decimals, but this is not working…
andres.gtz
  • 624
  • 12
  • 22
1
vote
1 answer

How to use variables instead of column names for running new Migrations directly in the Controller

I'm using Laravel 8 and I wanted to run this code which insert two new columns, if the attribute name does not exist in the returned results of product_attr_info_correction column names. $allAttrs = Attribute::all(); $columns =…
1
vote
2 answers

Laravel Database migrations Schema builder custom column type

I am trying to create migrations with Laravel but I am in a situation where I need custom column type since the one I want isn't included in schema builder , which is "POLYGON". So I want to know, how I can create my custom column type, other than…
Tarvo Mäesepp
  • 4,477
  • 3
  • 44
  • 92
1
vote
2 answers

laravel migration use auto increment when its not primary

I'm trying to create a table with Laravel migrations but I'm having some trouble. I just need to create a table with a primary pair ('user_id' and 'media_id'), being 'inc' an auto increment. I can do it in MySQL, but I can't manage to do it with…
1
vote
1 answer

laravel schema builder, find columnType autoincrement

I'm working to update an existing database to use autoincremented primary keys. This DB currently has crazy named PK fields with custom values. I need to check each table first to see if it HAS an autoinc field first, then I want to drop it and…
caro
  • 863
  • 3
  • 15
  • 36
1
vote
0 answers

How to create a nested table in an object-relational database using Schema Builder in Laravel?

I have an object-relational database that has table 'software' with a nested table named 'installations'. I am used to using Schema Builder with relational databases, and describing my columns this way: $table->integer('column_name'); Now, how can I…
0
votes
0 answers

Laravel unable to set foreign key to NULL

I am trying to set a foreign key to null, deleted_by does not allow me to save null as the default value. I want to be able to set the deleted_by field to null when I create a product. I'm currently using a factory to generate the product but I am…
1
2