V
V
Vanya Huk2018-03-18 20:51:36
ORM
Vanya Huk, 2018-03-18 20:51:36

How to link 4 tables in laravel ORM?

There are 4 tables:
transport_types

  • id
  • name
body_transport_types
  • id
  • body_id
  • transport_type_id
bodies
  • id
  • slug
body_descriptions
  • id
  • name
  • body_id
  • language_id

and there is a model
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Transport_type extends Model
{


    public static function callId( $id )
    {
        return self::whereId( $id ) -> firstOrFail();
    }

    public function bodies( $language_id = null )
    {
     }
}

you need to connect 4 tables with one query, so that it looks something like this:
$bodies = Transport_type::callId( 6 ) -> bodies ( 1 ) ;

and the $bodies variable had names in the appropriate language

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kuznetsov, 2018-03-19
@dima9595

Alternatively, polymorphic relationships.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question