without category

Pivot table relation in laravel

for implementing many to many relations in laravel you need to define a function in mode :

imagine we have entity user and entity teacher, and of course, we have a pivot table (something like user_teachers table)

let’s implement relation to teacher from user mode :

    public function teachers()
        return $this->belongsToMany(

// the class we want to set a relation -1 

// pivot table name -2

// the column refer to the class that we are write code in (user)

// the column that refer to number 1

// primary key in source table (user)

// primary key in target table (techer)
without category

Docker Cheet sheet