R
R
Richard_Novozhilov2018-06-16 16:28:26
Laravel
Richard_Novozhilov, 2018-06-16 16:28:26

Is it possible to transfer the database function during migration?

Hello.
PostgreSQL. Is it possible to somehow pass the database function as a default value in a field, for example, in "id"

Schema::create('users', function (Blueprint $table) {
<b>            $table->BigIncrements('id')->default("bounded_pseudo_encrypt(nextval('users_id_seq'::regclass)::integer)");</b>
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Talalaev, 2018-06-17
@neuotq

That won't work.
You have options either using model events (creating) and writing all the logic in php, or implement it in a trigger in PostgreSQL that will fire when a new record is created.

J
JhaoDa, 2018-06-17
@JhaoDa

Will help you \DB::raw(...). Read the documentation, there's a lot of interesting stuff in there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question