From c7e609f734489b599b3a1578b6c8de1239ef5112 Mon Sep 17 00:00:00 2001 From: Davide Date: Mon, 30 Nov 2015 20:58:42 +1100 Subject: [PATCH] ApiSubscriber model, migration and seeder. --- app/Models/ApiSubscriber.php | 41 +++++++++++++++++++ ...30_095335_create_api_subscribers_table.php | 39 ++++++++++++++++++ database/seeds/DatabaseSeeder.php | 23 ++++++++++- 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 app/Models/ApiSubscriber.php create mode 100644 database/migrations/2015_11_30_095335_create_api_subscribers_table.php diff --git a/app/Models/ApiSubscriber.php b/app/Models/ApiSubscriber.php new file mode 100644 index 0000000..e6ceb28 --- /dev/null +++ b/app/Models/ApiSubscriber.php @@ -0,0 +1,41 @@ +attributes['password'] = app('hash')->make($value); + } + + /** + * Get the identifier that will be stored in the subject claim of the JWT + * + * @return mixed + */ + public function getJWTIdentifier() + { + return $this->getKey(); + } + /** + * Return a key value array, containing any custom claims to be added to the JWT + * + * @return array + */ + public function getJWTCustomClaims() + { + return []; + } +} \ No newline at end of file diff --git a/database/migrations/2015_11_30_095335_create_api_subscribers_table.php b/database/migrations/2015_11_30_095335_create_api_subscribers_table.php new file mode 100644 index 0000000..2496930 --- /dev/null +++ b/database/migrations/2015_11_30_095335_create_api_subscribers_table.php @@ -0,0 +1,39 @@ +increments('api_subscriber_id'); + $table->string('email', 255); + $table->string('password', 255); + $table->timestamps(); + $table->softDeletes(); + + // unique key + $table->unique('email'); + + // indexes + $table->index(['email', 'password']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('api_subscribers'); + } +} diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index fb9e600..36073ea 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -14,8 +14,29 @@ public function run() { Model::unguard(); - // $this->call('UserTableSeeder'); + $this->call('DefaultPopulator'); Model::reguard(); } } + +/** + * Class DefaultPopulator + */ +class DefaultPopulator extends Seeder +{ + public function run() + { + $ApiSubscriber = App\Models\ApiSubscriber::create( + [ + 'email' => 'test@user.dev', + 'password' => 'secret', + ] + ); + + unset($ApiSubscriber); + return; + } + + +} \ No newline at end of file