B
B
BonBon Slick2016-12-12 15:33:05
Laravel
BonBon Slick, 2016-12-12 15:33:05

Why 2 different entries belongsToMany(Tag::class) and belongsToMany('App\Tag') if the result is identical?

It seems to work fine with both entries, in one option we specify the class, and in the other through the class path. I do not see the difference, how best to record?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Nesmeyanov, 2016-12-12
@BonBonSlick

I propose to get acquainted with the language, more specifically with php version 5.5: php.net/manual/en/language.oop5.basic.php

U
UnQuaiz, 2016-12-12
@UnQuaiz

Everything is obvious. If you use namespaces (and you do), it's more convenient to specify the class name without a namespace.
If you have a model in the namespace `Very\Super\Long\Name\Spa\ce\` then which entry will be shorter (do not forget to add a class to the "use" section if required):

belongsToMany( Tag::class )
or
belongsToMany( 'Very\Super\Long\Name\Spa\ce\Tag' )
?
This is the first benefit.
The second benefit - if you suddenly decide to rename the `Tag` class to `Metka` - you can easily do this by refactoring, and if you have a class specified by a string, then you will look for a mention of a string with the class name in the files. The same thing - if suddenly you need to move the Tag class from one namespace to another.
Well, definitely read the mana.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question