laravel relations find

Solutions on MaxInterview for laravel relations find by the best coders in the world

showing results for - "laravel relations find"
Lorenzo
13 Apr 2018
1$comment = Post::find(1)->comments()
2                    ->where('title', 'foo')
3                    ->first();
Lotta
25 Mar 2016
1return $this->hasMany(Comment::class, 'foreign_key');
2
3return $this->hasMany(Comment::class, 'foreign_key', 'local_key');
Gabriel
01 Apr 2018
1/**
2 * Get the user's most recent order.
3 */
4public function latestOrder()
5{
6    return $this->hasOne(Order::class)->latestOfMany();
7}
Rafael
07 Jan 2019
1class Project extends Model
2{
3    public function deployments()
4    {
5        return $this->hasManyThrough(
6            Deployment::class,
7            Environment::class,
8            'project_id', // Foreign key on the environments table...
9            'environment_id', // Foreign key on the deployments table...
10            'id', // Local key on the projects table...
11            'id' // Local key on the environments table...
12        );
13    }
14}
Ella
14 Jan 2021
1/**
2 * Get the current pricing for the product.
3 */
4public function currentPricing()
5{
6    return $this->hasOne(Price::class)->ofMany([
7        'published_at' => 'max',
8        'id' => 'max',
9    ], function ($query) {
10        $query->where('published_at', '<', now());
11    });
12}
Manuela
02 Sep 2016
1return $this->belongsToMany(Role::class, 'role_user');
Lorenzo
29 Aug 2019
1<?php
2
3namespace App\Models;
4
5use Illuminate\Database\Eloquent\Model;
6
7class Comment extends Model
8{
9    /**
10     * Get the post that owns the comment.
11     */
12    public function post()
13    {
14        return $this->belongsTo(Post::class);
15    }
16}
Opal
23 Jan 2018
1/**
2 * Get the user's oldest order.
3 */
4public function oldestOrder()
5{
6    return $this->hasOne(Order::class)->oldestOfMany();
7}
Luis
05 Jun 2017
1use App\Models\User;
2
3$user = User::find(1);
4
5foreach ($user->roles as $role) {
6    //
7}
Perrie
18 Jul 2017
1<?php
2
3namespace App\Models;
4
5use Illuminate\Database\Eloquent\Model;
6
7class Mechanic extends Model
8{
9    /**
10     * Get the car's owner.
11     */
12    public function carOwner()
13    {
14        return $this->hasOneThrough(Owner::class, Car::class);
15    }
16}
queries leading to this page
get relations laraveladd to has many relationship in laravellaravel find relationshiphow to get all the relations laravelhas many to return a single relationship laravelfind with relation table laravelhow to define relationship in laravelrelationship in laravel with examplerelationship model laravellaravel eloquent find model with all relationsexplain laravel relationshiprelationship models laravelhas many relationship laravelhas one relationship in laravelrelationship with laravelwhere on has many relationship laravellaravel relationship with relationshiprelationship laravellaravel eloquent relationship findlaravel has multiple relationshiplaravel relationship tutorialwith laravel relationshiplaravel relations wherehow to specific data has many relationship via with in laravellaravel get relation from stringlaravel relationship createlaravel has many relationship laravel having relationslaravel has one relationshiprelationship laravel examplelaravel relations searchlaravel relationshiptslaravel relationship withrelationship with relationship laravelrelationship in laravel exampleuseing relationship in laravelhow to relationship in laravaluse relationship in laravellaravel 7 get from relationsall about relationship in laravellaravel eloquent relationship syntaxuse and laravel relationshiplaravel has many relation on same tablerelations in models laravellaravel find without relationsdocs laravel relationshiphow to setup has many through relationship laravellaravel where on relationseloquent relationshiplaravel eloquent get with relationsreturning find with relation laravellaravel database relationshiplaravel find all relations on a modelrelationship using with in laravaleloquent get relations wheredefine relationship in laravel modellaravel find relation by idsearch laravel where relationslaravel single table has many relationshiplaravel find in relationshiplaravel how to elquont relationshiplaravel has many and belongs to many relationshiplaravel with relationshiphow to specific data has many relationship via select in laravellaravel explain with relationshiplaravel eloquent get relations with recordlaravel relationshipwhere has for many to many relationship laravellaravel has one relationship examplefind with relation laravellravel relationshiplaravel find with relationrelationship in laravalrelationship of relationship in laravellaravel relationshipalaravel has many relationship return one recordlaravel relationship example relation model laravelfind using relationship laravelrelations in laravellaravel model find with relationlaravel relationship datarelationship in laravellaravel relationship tablelaravel relationship has onelaravel get relations from modelhow do you create relationship in laravellaravel relationship 28 29has many relationship with latest laravelreturning find with relationtionships laravellaravel equlatnt relations model searchlaravel eloquent relationshiplaravel relations find