morph relation laravel

Solutions on MaxInterview for morph relation laravel by the best coders in the world

showing results for - "morph relation laravel"
Emerson
02 Jan 2019
1You may register the morphMap in the boot function of your 
2App\Providers\AppServiceProvider class or create a separate service provider 
3if you wish.
4
5use Illuminate\Database\Eloquent\Relations\Relation;
6
7Relation::morphMap([
8    'post' => 'App\Models\Post',
9    'video' => 'App\Models\Video',
10]);
Monica
02 May 2017
1posts
2    id - integer
3    title - string
4    body - text
5
6videos
7    id - integer
8    title - string
9    url - string
10
11comments
12    id - integer
13    body - text
14    commentable_id - integer
15    commentable_type - string
Ruben
12 Nov 2020
1<?php
2
3namespace App\Models;
4
5use Illuminate\Database\Eloquent\Model;
6
7class Comment extends Model
8{
9    /**
10     * Get the parent commentable model (post or video).
11     */
12    public function commentable()
13    {
14        return $this->morphTo();
15    }
16}
17
18class Post extends Model
19{
20    /**
21     * Get all of the post's comments.
22     */
23    public function comments()
24    {
25        return $this->morphMany(Comment::class, 'commentable');
26    }
27}
28
29class Video extends Model
30{
31    /**
32     * Get all of the video's comments.
33     */
34    public function comments()
35    {
36        return $this->morphMany(Comment::class, 'commentable');
37    }
38}
queries leading to this page
laravel many to many relationship custom pivotlaravel polymorphic one to one store examplemostrar morph tables laravelcreating via doubler relationship in laravellaravel polymorphic pivot tablelaravel polymorphic createwhere morphlaravel morphto count for modellaravel get morphlaravel morph with additional relationshipmorphto relation laravellaravel morph throughpolymorphic eloquent 2 wherepolymorphic eloquent wherelaravel polimorficlaravel morph data to modelwhere morph laravellaravel query polymorphic relationshiplaravel morph oneeloquent morph relationshiplaravel morph with relationshow to check which class in polymorphism relationship laravelmorphto laravellaravel polymorphic relationship one to many eloquentlaravel get morph relation in wherelaravel polymorphic relationship one to manylaravel morphmany relationlaravel polymorphic one to one examplewherehasmorph laravellaravel package add morph relationship with userspolymorphic relationshipmorph relationship laravelmorphmany relationship in laravel in laravelwhere to use morph relationships in laravelpolymorphic many to manylaravel morph relationshipmorph in laravelmorph relation laravel storepolymorph laravellaravel morphtomany examplelaravel polymorphic relationship examplemorph relattion laraveldefine relation belong to many in laravellaravel polymorphic relationship one to many eloquent storelaravel wherehasmorph all related modelslaravel with morph relationmorph relation in laravellaravel polymorphic migrationlaravel posts relationshipslaravel morph relation by table namelaravel get morph relation manuallyrelation morphmap laravelpolymorphic eloquent 2 wherlaravel relationships set morph manyreturn model with relationship laravelhow to attach morphto realtion laravellaravel relation ship morphlaravel make morph relationlaravel morphmany create manylaravel polymorphic relationshipone to many polymorphic laravellaravel docs polymorphic many to manymorph relation laravelpolymorphic relationship laravellaravel polymorphic referencelaravel morphmanyload eager loading laravellaravel morph relationmorphmany relation in laravel in laravellaravel polymorphic relation morphto child modelmorphmany laravelrelation 1 3a1 laravel morphmorph relation with laravelmorph relation in laravellaravel difference between one to many and polymorphic relationslaravel polymorphicmorphs relation laravellaravel create morph relationlaravel fill relationshipslaravel with morph and relationlaravel model morphtolaravel create morph relationshiplaravel morphtolaravel polymorphismlaravel hasmorphmorph relation in with function example laravelmorph relation in with example laravelpolymorphic relationship in laravellaravel polymorphism migrationmorph relation laravel createlaravel where morphmorphs laravelwith morph relation in laravel 8morphto 28 29 relation in laravellaravel morph relation use table namelaravel polymorphic relationslaravel morph by relationlaravel morph manylaravel morph one vs manytaggable polymorphic migration laravellaravel morphpolymorphic laravellaravel query by morph typemorph relation laravel examplepolymorphism laravelwhere has morph laraveleloquent morphlaravel add morph relationlaravel morph include relationslaravel polymorphic relationshipslaravel morph with relationshiplaravel relationship morphbelongs to many through laravelmorphmany laravel exemplelaravel morph one relationshipcreate morph relationship in laravelmorph relations laravellaravel polymorphic relationships morphto child modelmorphed by laravelmorph laravelone to one polymorphicmorphmany relation in laravelone to one polymorphic laravelpolymorphic one to one laravelpolymorphic relationship laravel examplemorph relation laravel