diff --git a/app/Models/Meta.php b/app/Models/Meta.php new file mode 100644 index 00000000..b590ef82 --- /dev/null +++ b/app/Models/Meta.php @@ -0,0 +1,68 @@ + + */ +class Meta extends Model +{ + use ValidatingTrait; + + /** + * The attributes that should be casted to native types. + * + * @var string[] + */ + protected $casts = [ + 'id' => 'int', + 'key' => 'string', + 'value' => 'json', + 'meta_id' => 'int', + 'meta_type' => 'string', + ]; + + /** + * The validation rules. + * + * @var string[] + */ + public $rules = [ + 'id' => 'nullable|int|min:1', + 'key' => 'required|string', + 'value' => 'nullable', + 'meta_id' => 'required|int', + 'meta_type' => 'required|string', + ]; + + /** + * The table associated with the model. + * + * @var string + */ + protected $table = 'meta'; + + /** + * Get all of the owning meta models. + * + * @return \Illuminate\Database\Eloquent\Relations\MorphTo + */ + public function meta() + { + return $this->morphTo(); + } +} diff --git a/database/migrations/2017_06_13_181049_CreateMetaTable.php b/database/migrations/2017_06_13_181049_CreateMetaTable.php new file mode 100644 index 00000000..30f73b14 --- /dev/null +++ b/database/migrations/2017_06_13_181049_CreateMetaTable.php @@ -0,0 +1,46 @@ +increments('id'); + $table->string('key')->index(); + $table->string('value'); + $table->integer('meta_id')->unsigned(); + $table->string('meta_type'); + $table->timestamps(); + + $table->index(['meta_id', 'meta_type']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('meta'); + } +}