jeudi 2 novembre 2017

Laravel, using model method as property

I am new to Laravel and playing around with it. Sorry if this is a silly question. I just could not figure out how eloquent relationships work. For example:

// we have posts and comments related to them
class Post extends Model
{
    public function comments(){
        return $this->hasMany(Comment::class);
    }
}

Now we can do this to get comments of the specified post:

$comments = $post->comments;

The first question is: how can be this possible. Where in Laravel the name of the method declared as a property.

The second question is: how can I use Comment class without calling it on the head of the file with 'use' statement. (use App\Comments)

Thanks.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2zbddiJ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire