“Laravel -Beziehungen finden” Code-Antworten

Laravel -Beziehungen finden

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

Laravel -Beziehungen finden

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

Laravel -Beziehungen finden

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

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

Laravel -Beziehungen finden

use App\Models\User;

$user = User::find(1);

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

Laravel -Beziehungen finden

use App\Models\Comment;

$comment = Comment::find(1);

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

Laravel -Beziehungen finden

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

Laravel -Beziehungen finden

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

Laravel -Beziehungen finden

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

Laravel -Beziehungen finden

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

Laravel -Beziehungen finden

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

Ähnliche Antworten wie “Laravel -Beziehungen finden”

Fragen ähnlich wie “Laravel -Beziehungen finden”

Weitere verwandte Antworten zu “Laravel -Beziehungen finden” auf PHP

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen