Using Foreign Keys Laravel 5.6

1

Good afternoon everyone. I created a migration "clients" in the laravel that receives 3 foreign keys coming from entities: modalities, requests and locals.

In my view when registering a client and viewing in phpmyadmin I see that all the data is saved with their respective names, however in this my clients table, the modal, request and locals columns are saved only the id.

For example:

In the mode select the user chooses the first select item that is Special.

In the select of orders the user chooses the second item of the select that is Varied.

In the select of locals the user chooses the third item of the select that is São Paulo.

If I go there in phpmyadmin to see how it was in the register you will be in these columns respectively: 1, 2 and 3.

Is it anyway or am I doing something wrong so the name is not appearing?

My clients migration looks like this:

$table->increments('id');
$table->string('nome_cliente',80);
$table->string('email_cliente',80)->unique();
$table->string('endereco',50);
$table->string('situacao',20);
$table->integer('modalidade_id')->unsigned();
$table->foreign('modalidade_id')->references('id')->on('modalidades');
$table->integer('pedido_id')->unsigned();
$table->foreign('pedido_id')->references('id')->on('pedidos');
$table->integer('locals_id')->unsigned();
$table->foreign('locals_id')->references('id')->on('locals');

            $table->softDeletes();

            $table->timestamps();
    
asked by anonymous 20.09.2018 / 20:45

1 answer

0

Foreign key is the field that establishes the relationship between two tables.

Thus, one column corresponds to the same column that is the primary key of another table .

In this way, you must specify in the table that contains the foreign key what these columns are and to which table it is related.

The database will check if all fields that refer to the table are specified, and by default the vast majority of databases by convention use the ids of each table.

It's easier to compare an int , than a string, do not you think? For a string can contain variations between lowercase, uppercase, and size, and an int will always be an int.

    
21.09.2018 / 14:22