I am trying to use a trait as a type for my Laravel resource controllers.
Controller Method:
public function store(CreateCommentRequest $request, Commentable $commentable)
Which Commentableis the type of attribute type that my Eloquent models use.
The symptom is Commentableas follows:
namespace App\Models\Morphs;
use App\Comment;
trait Commentable
{
   
    public function Comments()
    {
        return $this->morphMany(Comment::class, 'commentable')->orderBy('created_at', 'DESC');
    }
}
In my routing, I have:
Route::resource('order.comment', 'CommentController')
Route::resource('fulfillments.comment', 'CommentController')
Both orders and executions may have comments, so they use the same controller, since the code will be the same.
However, when I send a message to order/{order}/comment, I get the following error:
Lighten \ Contracts \ Container \ BindingResolutionException
The purpose of [App \ Models \ Morphs \ Commentable] is not real.
Is this even possible?
source