“Znajdź stosunki laravel” Kod odpowiedzi

Znajdź stosunki laravel

/**
 * 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

Znajdź stosunki laravel

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

Znajdź stosunki laravel

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

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

Znajdź stosunki laravel

use App\Models\User;

$user = User::find(1);

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

Znajdź stosunki laravel

use App\Models\Comment;

$comment = Comment::find(1);

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

Znajdź stosunki laravel

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

Znajdź stosunki laravel

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

Znajdź stosunki laravel

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

Znajdź stosunki laravel

<?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

Znajdź stosunki laravel

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

Odpowiedzi podobne do “Znajdź stosunki laravel”

Pytania podobne do “Znajdź stosunki laravel”

Więcej pokrewnych odpowiedzi na “Znajdź stosunki laravel” w PHP

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu