Answers for "laravel relations find"

PHP
0

laravel relations find

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

laravel relations find

return $this->belongsToMany(Role::class, 'role_user', 'user_id', 'role_id');
Posted by: Guest on June-10-2021
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

class Mechanic extends Model
{
    /**
     * Get the car's owner.
     */
    public function carOwner()
    {
        return $this->hasOneThrough(
            Owner::class,
            Car::class,
            'mechanic_id', // Foreign key on the cars table...
            'car_id', // Foreign key on the owners table...
            'id', // Local key on the mechanics table...
            'id' // Local key on the cars table...
        );
    }
}
Posted by: Guest on June-10-2021
0

laravel relations find

/**
 * Get the current pricing for the product.
 */
public function currentPricing()
{
    return $this->hasOne(Price::class)->ofMany([
        'published_at' => 'max',
        'id' => 'max',
    ], function ($query) {
        $query->where('published_at', '<', now());
    });
}
Posted by: Guest on June-10-2021
0

laravel relations find

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

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

$roles = User::find(1)->roles()->orderBy('name')->get();
Posted by: Guest on June-10-2021
0

laravel relations find

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Mechanic extends Model
{
    /**
     * Get the car's owner.
     */
    public function carOwner()
    {
        return $this->hasOneThrough(Owner::class, Car::class);
    }
}
Posted by: Guest on May-06-2021
0

laravel relations find

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

laravel relations find

use App\Models\Post;

$comments = Post::find(1)->comments;

foreach ($comments as $comment) {
    //
}
Posted by: Guest on January-28-2021

Code answers related to "laravel relations find"

Browse Popular Code Answers by Language