dillingham/morphable

morphable functionality

1.0.1 2019-08-23 17:09 UTC

This package is auto-updated.

Last update: 2024-03-29 03:58:52 UTC


README

Latest Version on Github Total Downloads Twitter Follow

composer require dillingham/morphable
  • Add Morphable to a model
  • Add ResolveMorphs to your base controller
  • Fill $morphable on a controller with model classes
  • Submit type and id to a controller
  • adds ->forMorph($model) to fill object_type, object_id
<?php

class CommentController extends Controller
{
    use ResolveMorphs;
    
    public $morphable = [
        \App\Post::class
    ];

    public function store()
    {
        $model = $this->resolveMorph();

        $comment = new Comment;
        $comment->forMorph($model);
        $comment->save();
    }
}