diff options
author | Camil Staps | 2015-05-14 11:18:12 +0200 |
---|---|---|
committer | Camil Staps | 2015-05-14 11:18:12 +0200 |
commit | a012ea9e7d5dd0baadb549e1460a8339224f37a5 (patch) | |
tree | a74414754eb8d00d21d92d1ca5be274235ac8e52 /src | |
parent | Password reminders start (diff) |
Own Model class; new namespaces Database and Controllers; RFC2822 dates
Diffstat (limited to 'src')
19 files changed, 75 insertions, 46 deletions
diff --git a/src/CamilStaps/BotleaguesApi/Bot.php b/src/CamilStaps/BotleaguesApi/Database/Bot.php index 04fa2c7..f0be0fc 100644 --- a/src/CamilStaps/BotleaguesApi/Bot.php +++ b/src/CamilStaps/BotleaguesApi/Database/Bot.php @@ -1,7 +1,5 @@ <?php -namespace CamilStaps\BotleaguesApi; - -use Illuminate\Database\Eloquent\Model; +namespace CamilStaps\BotleaguesApi\Database; class Bot extends Model { diff --git a/src/CamilStaps/BotleaguesApi/Competition.php b/src/CamilStaps/BotleaguesApi/Database/Competition.php index a8da665..c355c08 100644 --- a/src/CamilStaps/BotleaguesApi/Competition.php +++ b/src/CamilStaps/BotleaguesApi/Database/Competition.php @@ -1,7 +1,5 @@ <?php -namespace CamilStaps\BotleaguesApi; - -use Illuminate\Database\Eloquent\Model; +namespace CamilStaps\BotleaguesApi\Database; class Competition extends Model { diff --git a/src/CamilStaps/BotleaguesApi/CompetitionType.php b/src/CamilStaps/BotleaguesApi/Database/CompetitionType.php index b9fb426..0107ffe 100644 --- a/src/CamilStaps/BotleaguesApi/CompetitionType.php +++ b/src/CamilStaps/BotleaguesApi/Database/CompetitionType.php @@ -1,7 +1,5 @@ <?php -namespace CamilStaps\BotleaguesApi; - -use Illuminate\Database\Eloquent\Model; +namespace CamilStaps\BotleaguesApi\Database; class CompetitionType extends Model { diff --git a/src/CamilStaps/BotleaguesApi/Game.php b/src/CamilStaps/BotleaguesApi/Database/Game.php index 3823ab2..a8b0649 100644 --- a/src/CamilStaps/BotleaguesApi/Game.php +++ b/src/CamilStaps/BotleaguesApi/Database/Game.php @@ -1,7 +1,5 @@ <?php -namespace CamilStaps\BotleaguesApi; - -use Illuminate\Database\Eloquent\Model; +namespace CamilStaps\BotleaguesApi\Database; class Game extends Model { diff --git a/src/CamilStaps/BotleaguesApi/Database/Model.php b/src/CamilStaps/BotleaguesApi/Database/Model.php new file mode 100644 index 0000000..27bd1fc --- /dev/null +++ b/src/CamilStaps/BotleaguesApi/Database/Model.php @@ -0,0 +1,30 @@ +<?php +/** + * Created by PhpStorm. + * User: camilstaps + * Date: 14-5-15 + * Time: 10:47 + */ + +namespace CamilStaps\BotleaguesApi\Database; + +use Carbon\Carbon; + + +class Model extends \Illuminate\Database\Eloquent\Model { + + protected $date_format = Carbon::RFC2822; + + protected function formatDate($date) { + return Carbon::parse($date)->format($this->date_format); + } + + public function getCreatedAtAttribute($attr) { + return $this->formatDate($attr); + } + + public function getUpdatedAtAttribute($attr) { + return $this->formatDate($attr); + } + +}
\ No newline at end of file diff --git a/src/CamilStaps/BotleaguesApi/Participant.php b/src/CamilStaps/BotleaguesApi/Database/Participant.php index 65e1261..584d00c 100644 --- a/src/CamilStaps/BotleaguesApi/Participant.php +++ b/src/CamilStaps/BotleaguesApi/Database/Participant.php @@ -1,7 +1,5 @@ <?php -namespace CamilStaps\BotleaguesApi; - -use Illuminate\Database\Eloquent\Model; +namespace CamilStaps\BotleaguesApi\Database; class Participant extends Model { diff --git a/src/CamilStaps/BotleaguesApi/PasswordReminder.php b/src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php index a129dc8..40bc578 100644 --- a/src/CamilStaps/BotleaguesApi/PasswordReminder.php +++ b/src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php @@ -6,10 +6,8 @@ * Time: 13:12 */ -namespace CamilStaps\BotleaguesApi; +namespace CamilStaps\BotleaguesApi\Database; - -use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Mail; class PasswordReminder extends Model { diff --git a/src/CamilStaps/BotleaguesApi/User.php b/src/CamilStaps/BotleaguesApi/Database/User.php index 560f737..383cc38 100644 --- a/src/CamilStaps/BotleaguesApi/User.php +++ b/src/CamilStaps/BotleaguesApi/Database/User.php @@ -1,9 +1,8 @@ <?php -namespace CamilStaps\BotleaguesApi; +namespace CamilStaps\BotleaguesApi\Database; use Illuminate\Auth\Reminders\RemindableInterface; use Illuminate\Auth\UserInterface; -use Illuminate\Database\Eloquent\Model; class User extends Model implements UserInterface, RemindableInterface { diff --git a/src/CamilStaps/BotleaguesApi/UserToken.php b/src/CamilStaps/BotleaguesApi/Database/UserToken.php index 9909f6a..92b03b8 100644 --- a/src/CamilStaps/BotleaguesApi/UserToken.php +++ b/src/CamilStaps/BotleaguesApi/Database/UserToken.php @@ -1,13 +1,12 @@ <?php -namespace CamilStaps\BotleaguesApi; - -use Illuminate\Database\Eloquent\Model; +namespace CamilStaps\BotleaguesApi\Database; class UserToken extends Model { protected $table = 'user_tokens'; protected $hidden = ['token']; protected $fillable = ['userId', 'token', 'valid_till']; + protected $dates = ['created_at', 'updated_at', 'valid_till']; /** * Override the parent's save() function to automatically update the valid_till timestamp @@ -18,4 +17,8 @@ class UserToken extends Model { return parent::save($options); } + public function getValidTillAttribute($attr) { + return $this->formatDate($attr); + } + }
\ No newline at end of file diff --git a/src/controllers/BaseController.php b/src/controllers/BaseController.php index 2cc52c5..35117e2 100644 --- a/src/controllers/BaseController.php +++ b/src/controllers/BaseController.php @@ -1,5 +1,5 @@ <?php -namespace CamilStaps\BotleaguesApi; +namespace CamilStaps\BotleaguesApi\Controllers; use \Dingo\Api\Routing\ControllerTrait; diff --git a/src/controllers/BotController.php b/src/controllers/BotController.php index 9349ea8..89aef8c 100644 --- a/src/controllers/BotController.php +++ b/src/controllers/BotController.php @@ -1,5 +1,7 @@ <?php -namespace CamilStaps\BotleaguesApi; +namespace CamilStaps\BotleaguesApi\Controllers; + +use CamilStaps\BotleaguesApi\Database\Bot; class BotController extends BaseController { diff --git a/src/controllers/CompetitionController.php b/src/controllers/CompetitionController.php index c169492..f54c11d 100644 --- a/src/controllers/CompetitionController.php +++ b/src/controllers/CompetitionController.php @@ -1,6 +1,7 @@ <?php -namespace CamilStaps\BotleaguesApi; +namespace CamilStaps\BotleaguesApi\Controllers; +use CamilStaps\BotleaguesApi\Database\Competition; use Illuminate\Support\Facades\Input; class CompetitionController extends BaseController { diff --git a/src/controllers/CompetitionTypeController.php b/src/controllers/CompetitionTypeController.php index a29d5db..993973c 100644 --- a/src/controllers/CompetitionTypeController.php +++ b/src/controllers/CompetitionTypeController.php @@ -1,6 +1,7 @@ <?php -namespace CamilStaps\BotleaguesApi; +namespace CamilStaps\BotleaguesApi\Controllers; +use CamilStaps\BotleaguesApi\Database\CompetitionType; use Illuminate\Support\Facades\Input; class CompetitionTypeController extends BaseController { diff --git a/src/controllers/GameController.php b/src/controllers/GameController.php index 15062c2..0fbcc1b 100644 --- a/src/controllers/GameController.php +++ b/src/controllers/GameController.php @@ -1,6 +1,7 @@ <?php -namespace CamilStaps\BotleaguesApi; +namespace CamilStaps\BotleaguesApi\Controllers; +use CamilStaps\BotleaguesApi\Database\Game; use Illuminate\Support\Facades\Input; class GameController extends BaseController { diff --git a/src/controllers/ParticipantController.php b/src/controllers/ParticipantController.php index a493146..11d7dd9 100644 --- a/src/controllers/ParticipantController.php +++ b/src/controllers/ParticipantController.php @@ -1,6 +1,7 @@ <?php -namespace CamilStaps\BotleaguesApi; +namespace CamilStaps\BotleaguesApi\Controllers; +use CamilStaps\BotleaguesApi\Database\Participant; use Illuminate\Support\Facades\Input; class ParticipantController extends BaseController { diff --git a/src/controllers/PasswordReminderController.php b/src/controllers/PasswordReminderController.php index 0c2a087..622e92c 100644 --- a/src/controllers/PasswordReminderController.php +++ b/src/controllers/PasswordReminderController.php @@ -6,8 +6,9 @@ * Time: 13:13 */ -namespace CamilStaps\BotleaguesApi; +namespace CamilStaps\BotleaguesApi\Controllers; +use CamilStaps\BotleaguesApi\Database\PasswordReminder; use Illuminate\Support\Facades\Input; class PasswordReminderController extends BaseController { diff --git a/src/controllers/UserController.php b/src/controllers/UserController.php index 90e43ce..a64ed71 100644 --- a/src/controllers/UserController.php +++ b/src/controllers/UserController.php @@ -1,6 +1,7 @@ <?php -namespace CamilStaps\BotleaguesApi; +namespace CamilStaps\BotleaguesApi\Controllers; +use CamilStaps\BotleaguesApi\Database\User; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Input; diff --git a/src/controllers/UserTokenController.php b/src/controllers/UserTokenController.php index 5a6099b..20bd06c 100644 --- a/src/controllers/UserTokenController.php +++ b/src/controllers/UserTokenController.php @@ -1,6 +1,7 @@ <?php -namespace CamilStaps\BotleaguesApi; +namespace CamilStaps\BotleaguesApi\Controllers; +use CamilStaps\BotleaguesApi\Database\UserToken; use Illuminate\Support\Facades\Input; use Illuminate\Support\Facades\Auth; diff --git a/src/routes.php b/src/routes.php index 8ec4e38..6885443 100644 --- a/src/routes.php +++ b/src/routes.php @@ -3,54 +3,54 @@ Route::group(array('https'), function() { Route::api(['version' => 'v1', 'protected' => false], function () { - Route::resource('bot', 'CamilStaps\BotleaguesApi\BotController', + Route::resource('bot', 'CamilStaps\BotleaguesApi\Controllers\BotController', ['only' => ['index','show']]); - Route::resource('competition', 'CamilStaps\BotleaguesApi\CompetitionController', + Route::resource('competition', 'CamilStaps\BotleaguesApi\Controllers\CompetitionController', ['only' => ['index','show']]); - Route::resource('competition_type', 'CamilStaps\BotleaguesApi\CompetitionTypeController', + Route::resource('competition_type', 'CamilStaps\BotleaguesApi\Controllers\CompetitionTypeController', ['only' => ['index','show']]); - Route::resource('game', 'CamilStaps\BotleaguesApi\GameController', + Route::resource('game', 'CamilStaps\BotleaguesApi\Controllers\GameController', ['only' => ['index','show']]); - Route::resource('participant', 'CamilStaps\BotleaguesApi\ParticipantController', + Route::resource('participant', 'CamilStaps\BotleaguesApi\Controllers\ParticipantController', ['only' => ['index','show']]); - Route::resource('user', 'CamilStaps\BotleaguesApi\UserController', + Route::resource('user', 'CamilStaps\BotleaguesApi\Controllers\UserController', ['only' => ['index','show','store']]); - Route::resource('password_reminder', 'CamilStaps\BotleaguesApi\PasswordReminderController', + Route::resource('password_reminder', 'CamilStaps\BotleaguesApi\Controllers\PasswordReminderController', ['only' => ['store']]); }); Route::api(['version' => 'v1', 'protected' => true, 'providers' => 'basic'], function () { - Route::resource('user_token', 'CamilStaps\BotleaguesApi\UserTokenController', + Route::resource('user_token', 'CamilStaps\BotleaguesApi\Controllers\UserTokenController', ['only' => ['store']]); }); Route::api(['version' => 'v1', 'protected' => true, 'providers' => 'token'], function () { - Route::resource('bot', 'CamilStaps\BotleaguesApi\BotController', + Route::resource('bot', 'CamilStaps\BotleaguesApi\Controllers\BotController', ['except' => ['index', 'show', 'create','edit']]); - Route::resource('user', 'CamilStaps\BotleaguesApi\UserController', + Route::resource('user', 'CamilStaps\BotleaguesApi\Controllers\UserController', ['except' => ['index', 'show', 'create','edit','store']]); - Route::resource('user_token', 'CamilStaps\BotleaguesApi\UserTokenController', + Route::resource('user_token', 'CamilStaps\BotleaguesApi\Controllers\UserTokenController', ['only' => ['index', 'show']]); Route::group(array('before' => 'administrator'), function() { - Route::resource('competition', 'CamilStaps\BotleaguesApi\CompetitionController', + Route::resource('competition', 'CamilStaps\BotleaguesApi\Controllers\CompetitionController', ['except' => ['index', 'show', 'create', 'edit']]); - Route::resource('competition_type', 'CamilStaps\BotleaguesApi\CompetitionTypeController', + Route::resource('competition_type', 'CamilStaps\BotleaguesApi\Controllers\CompetitionTypeController', ['except' => ['index', 'show', 'create', 'edit']]); - Route::resource('game', 'CamilStaps\BotleaguesApi\GameController', + Route::resource('game', 'CamilStaps\BotleaguesApi\Controllers\GameController', ['except' => ['index', 'show', 'create','edit']]); }); |