Answers for "laravel eloquent get with relations"

PHP
0

laravel relations find

/**
 * Get the user's most recent order.
 */
public function latestOrder()
{
    return $this->hasOne(Order::class)->latestOfMany();
}
Posted by: Guest on June-10-2021
0

laravel relations find

$comment = Post::find(1)->comments()
                    ->where('title', 'foo')
                    ->first();
Posted by: Guest on May-26-2021
0

laravel relations find

<?php

namespace AppModels;

use IlluminateDatabaseEloquentModel;

class Comment extends Model
{
    /**
     * Get the post that owns the comment.
     */
    public function post()
    {
        return $this->belongsTo(Post::class);
    }
}
Posted by: Guest on June-10-2021
0

laravel relations find

return $this->belongsToMany(Role::class, 'role_user');
Posted by: Guest on June-10-2021
0

laravel relations find

return $this->hasMany(Comment::class, 'foreign_key');

return $this->hasMany(Comment::class, 'foreign_key', 'local_key');
Posted by: Guest on June-10-2021
0

laravel relations find

use AppModelsComment;

$comment = Comment::find(1);

return $comment->post->title;
Posted by: Guest on June-10-2021

Code answers related to "laravel eloquent get with relations"

Browse Popular Code Answers by Language