-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ApiSubscriber model, migration and seeder.
- Loading branch information
Showing
3 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php namespace App\Models; | ||
|
||
use Illuminate\Contracts\Auth\Authenticatable; | ||
use Illuminate\Database\Eloquent\Collection; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Tymon\JWTAuth\Contracts\JWTSubject; | ||
|
||
class ApiSubscriber extends Model implements Authenticatable, JWTSubject | ||
{ | ||
use \Illuminate\Auth\Authenticatable; | ||
|
||
protected $table = 'api_subscribers'; | ||
protected $primaryKey = 'api_subscriber_id'; | ||
|
||
/** | ||
* @param $value | ||
*/ | ||
public function setPasswordAttribute($value) | ||
{ | ||
$this->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 []; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
database/migrations/2015_11_30_095335_create_api_subscribers_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class CreateApiSubscribersTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('api_subscribers', function (Blueprint $table) { | ||
$table->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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' => '[email protected]', | ||
'password' => 'secret', | ||
] | ||
); | ||
|
||
unset($ApiSubscriber); | ||
return; | ||
} | ||
|
||
|
||
} |