I’d like to create some commentable models for a project, but I cannot find any references to create the comments migration script, I’ve only found this video on vimeo: Laravel 4 – Eloquent Collections & Polymorphic Relations.
Am I supposed to add the polymorphic columns explicitly?
Schema::create('comments',function($table){
$table->increments('id');
$table->text('body');
$table->string('commentable_type');
$table->integer('commentable_id');
$table->timestamps();
});
Question comes as the builder do expects the programmer when a key is a foreign key as in $table->foreign('user_id')->references('id')->on('users');
Polymorphic connections are nothing to do with Schema, they are an Eloquent feature which allows relationships to be built between any other type of model.
You can check the documentation for this:
http://four.laravel.com/docs/eloquent#relationships