vendredi 29 juin 2018

Laravel: One to Many Poly relation not updating automatically

3 types of posts: Personal, Business & Nature.

Below is the Post Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Relation;

Relation::morphMap([
          'Personal' => 'App\Personal',
          'Business' => 'App\Business',
          'Nature' => 'App\Nature',
        ]);

class Post extends Model
{
    public function postable()
    {
        return $this->morphTo();
    }        
}

Below is the Personal Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;    

class Personal extends Model
{
    public function posts()
    {
        return $this->morphMany(Post::class,'postable');
    }
}

Likewise Busines & Nature models.

When I manually enter the data in phpMyAdmin, the tinker shows the result as required, but when I create a post from front-end (via form), the posts table remains unchanged.

I tried googling, but nothing works! :(



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire