Guest User

Untitled

a guest
Feb 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. <?php
  2.  
  3. use IlluminateSupportFacadesSchema;
  4. use IlluminateDatabaseSchemaBlueprint;
  5. use IlluminateDatabaseMigrationsMigration;
  6.  
  7. class TableVideoResources extends Migration
  8. {
  9. public function up()
  10. {
  11. Schema::create('videoresources', function (Blueprint $table) {
  12. $table->increments('id');
  13. $table->string('title', 50);
  14. $table->timestamps();
  15. });
  16. }
  17. public function down()
  18. {
  19. Schema::dropIfExists('videoresources');
  20. }
  21. }
  22.  
  23. <?php
  24.  
  25. use IlluminateSupportFacadesSchema;
  26. use IlluminateDatabaseSchemaBlueprint;
  27. use IlluminateDatabaseMigrationsMigration;
  28.  
  29. class TableResources extends Migration
  30. {
  31. public function up()
  32. {
  33. Schema::create('resources', function (Blueprint $table) {
  34. $table->increments('id');
  35. $table->string('name', 50);
  36. $table->timestamps();
  37. $table->integer('resourceable_id')->unsigned();
  38. $table->string('resourceable_type', 100);
  39. });
  40. }
  41. public function down()
  42. {
  43. Schema::dropIfExists('resources');
  44. }
  45. }
  46.  
  47. <?php namespace AppModels;
  48.  
  49. use IlluminateDatabaseEloquentModel;
  50.  
  51. class Resource extends Model
  52. {
  53. protected $primaryKey = 'id';
  54. protected $table = 'resources';
  55. protected $fillable = ['name'];
  56. public $timestamps = true;
  57.  
  58. public function resourceable()
  59. {
  60. return $this->morphTo();
  61. }
  62. }
  63.  
  64. <?php namespace AppModels;
  65.  
  66. use IlluminateDatabaseEloquentModel;
  67.  
  68. class VideoResource extends Model
  69. {
  70. protected $primaryKey = 'id';
  71. protected $table = 'videoresources';
  72. protected $fillable = ['title'];
  73. public $timestamps = true;
  74.  
  75. public function resource()
  76. {
  77. return $this->morphOne(Resource::class, 'resourceable');
  78. }
  79. }
Add Comment
Please, Sign In to add comment