Illuminate\Database\Eloquent\Model::joiningTable PHP Method

joiningTable() public method

Get the joining table name for a many-to-many relation.
public joiningTable ( string $related ) : string
$related string
return string
    public function joiningTable($related)
    {
        // The joining table name, by convention, is simply the snake cased models
        // sorted alphabetically and concatenated with an underscore, so we can
        // just sort the models and join them together to get the table name.
        $base = Str::snake(class_basename($this));
        $related = Str::snake(class_basename($related));
        $models = [$related, $base];
        // Now that we have the model names in an array we can just sort them and
        // use the implode function to join them together with an underscores,
        // which is typically used by convention within the database system.
        sort($models);
        return strtolower(implode('_', $models));
    }
Model