Get a database value of another table in laravel

In laravel database relationships are simple, and to get a value of another table to another view based on the values you got in this view you simple connect these two tables with a relationship. 

Lets get a real world problem about this, For this I’ll get a website I’ve done before. 

lets say I’ve submitted a form and in this form I got a result. like in the image below.

Now based on this “ISFJ” result, I want to get a short description of this type from another table, where the descriptions are stored.

So what I’ve to do is to link them together So a the results belongs to a short description right?

to the Test class add this relationship code

public function tipi()
return $this->belongsTo(Tipi::class, 'finaltype', 'type');

so what we are doing there is connect the finaltype column which stores the ISFJ type, to the “type” table of the type description.

on the view, just add this code.

{!! $results->tipi->shortDescription !!}

So the $results variable is what you already use to connect to your table of this view, but you simply say use the connection mentioned above, in this case the function is public function tipi() so you used tipi as $results->tipi and at last what you want to get, in our case we need the short description.

and here you have it, based on the final type you get the short description