Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use IlluminateSupportFacadesSchema;
- use IlluminateDatabaseSchemaBlueprint;
- use IlluminateDatabaseMigrationsMigration;
- class TableVideoResources extends Migration
- {
- public function up()
- {
- Schema::create('videoresources', function (Blueprint $table) {
- $table->increments('id');
- $table->string('title', 50);
- $table->timestamps();
- });
- }
- public function down()
- {
- Schema::dropIfExists('videoresources');
- }
- }
- <?php
- use IlluminateSupportFacadesSchema;
- use IlluminateDatabaseSchemaBlueprint;
- use IlluminateDatabaseMigrationsMigration;
- class TableResources extends Migration
- {
- public function up()
- {
- Schema::create('resources', function (Blueprint $table) {
- $table->increments('id');
- $table->string('name', 50);
- $table->timestamps();
- $table->integer('resourceable_id')->unsigned();
- $table->string('resourceable_type', 100);
- });
- }
- public function down()
- {
- Schema::dropIfExists('resources');
- }
- }
- <?php namespace AppModels;
- use IlluminateDatabaseEloquentModel;
- class Resource extends Model
- {
- protected $primaryKey = 'id';
- protected $table = 'resources';
- protected $fillable = ['name'];
- public $timestamps = true;
- public function resourceable()
- {
- return $this->morphTo();
- }
- }
- <?php namespace AppModels;
- use IlluminateDatabaseEloquentModel;
- class VideoResource extends Model
- {
- protected $primaryKey = 'id';
- protected $table = 'videoresources';
- protected $fillable = ['title'];
- public $timestamps = true;
- public function resource()
- {
- return $this->morphOne(Resource::class, 'resourceable');
- }
- }
Add Comment
Please, Sign In to add comment