“Hubungan Laravel menemukan” Kode Jawaban

Hubungan Laravel menemukan

/**
 * 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());
    });
}
Sore Seal

Hubungan Laravel menemukan

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...
        );
    }
}
Sore Seal

Hubungan Laravel menemukan

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

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

Hubungan Laravel menemukan

use App\Models\User;

$user = User::find(1);

foreach ($user->roles as $role) {
    //
}
Sore Seal

Hubungan Laravel menemukan

use App\Models\Comment;

$comment = Comment::find(1);

return $comment->post->title;
Sore Seal

Hubungan Laravel menemukan

return $this->belongsToMany(Role::class, 'role_user');
Sore Seal

Hubungan Laravel menemukan

/**
 * Get the user's largest order.
 */
public function largestOrder()
{
    return $this->hasOne(Order::class)->ofMany('price', 'max');
}
Sore Seal

Hubungan Laravel menemukan

class Project extends Model
{
    public function deployments()
    {
        return $this->hasManyThrough(
            Deployment::class,
            Environment::class,
            'project_id', // Foreign key on the environments table...
            'environment_id', // Foreign key on the deployments table...
            'id', // Local key on the projects table...
            'id' // Local key on the environments table...
        );
    }
}
Sore Seal

Hubungan Laravel menemukan

<?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);
    }
}
Sore Seal

Hubungan Laravel menemukan

$roles = User::find(1)->roles()->orderBy('name')->get();
Sore Seal

Jawaban yang mirip dengan “Hubungan Laravel menemukan”

Pertanyaan yang mirip dengan “Hubungan Laravel menemukan”

Lebih banyak jawaban terkait untuk “Hubungan Laravel menemukan” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya