I'm reading "Up and Running Laravel" book and regularly come across examples like:
class Contact extends Model
{
public function phoneNumer()
{
return $this->hasOne(PhoneNumber::class);
}
}
The explanation in the book:
As you can tell, the methods defining realationships are on the Eloquent model itself ($this->hasOne()) and take, at least in this instance, the fully qualified class name of the class that you're relating them to.
Since I don't really understand it, I looked up php.net and found this:
The class keyword is also used for class name resolution. To obtain the fully qualified name of a class ClassName use ClassName::class. This is particularly useful with namespaced classes.
Is it just necessary so php knows that PhoneNumber is a class? In other words, if it was:
return $this->hasOne(PhoneNumber);
I guess I would get an error/warning because php has no idea that we are talking about the class? Otherwise, the return is within the class so I thought it should be clear that the class name is meant?
Could anyone explain to me like you would explain it to your 5 year old son?