Answers for "laravel find without relations"

PHP
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

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

$roles = User::find(1)->roles()->orderBy('name')->get();
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 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

use AppModelsUser;

$user = User::find(1);

foreach ($user->roles as $role) {
    //
}
Posted by: Guest on June-10-2021

Code answers related to "laravel find without relations"

Browse Popular Code Answers by Language