Skip to content

Commit

Permalink
ApiSubscriber model, migration and seeder.
Browse files Browse the repository at this point in the history
  • Loading branch information
0plus1 committed Nov 30, 2015
1 parent 453accc commit c7e609f
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 1 deletion.
41 changes: 41 additions & 0 deletions app/Models/ApiSubscriber.php
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 [];
}
}
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');
}
}
23 changes: 22 additions & 1 deletion database/seeds/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


}

0 comments on commit c7e609f

Please sign in to comment.