Use Laravel's built-in updater
This commit is contained in:
parent
3cf19d8656
commit
5332589b65
@ -139,7 +139,6 @@ class AuthController extends Controller
|
||||
$player->uid = $user->uid;
|
||||
$player->player_name = $request->get('player_name');
|
||||
$player->tid_skin = 0;
|
||||
$player->last_modified = get_datetime_string();
|
||||
$player->save();
|
||||
|
||||
event(new Events\PlayerWasAdded($player));
|
||||
|
@ -86,7 +86,6 @@ class PlayerController extends Controller
|
||||
$player->uid = $user->uid;
|
||||
$player->player_name = $request->input('player_name');
|
||||
$player->tid_skin = 0;
|
||||
$player->last_modified = get_datetime_string();
|
||||
$player->save();
|
||||
|
||||
event(new PlayerWasAdded($player));
|
||||
|
@ -9,6 +9,9 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Player extends Model
|
||||
{
|
||||
public const CREATED_AT = null;
|
||||
public const UPDATED_AT = 'last_modified';
|
||||
|
||||
/**
|
||||
* Json APIs.
|
||||
*/
|
||||
@ -21,7 +24,6 @@ class Player extends Model
|
||||
* Properties for Eloquent Model.
|
||||
*/
|
||||
public $primaryKey = 'pid';
|
||||
public $timestamps = false;
|
||||
protected $fillable = ['uid', 'player_name', 'last_modified'];
|
||||
|
||||
/**
|
||||
@ -99,8 +101,6 @@ class Player extends Model
|
||||
}
|
||||
}
|
||||
|
||||
$this->last_modified = get_datetime_string();
|
||||
|
||||
$this->save();
|
||||
|
||||
event(new PlayerProfileUpdated($this));
|
||||
@ -159,8 +159,7 @@ class Player extends Model
|
||||
public function rename($newName)
|
||||
{
|
||||
$this->update([
|
||||
'player_name' => $newName,
|
||||
'last_modified' => get_datetime_string(),
|
||||
'player_name' => $newName,
|
||||
]);
|
||||
|
||||
$this->player_name = $newName;
|
||||
@ -235,17 +234,4 @@ class Player extends Model
|
||||
|
||||
return json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the date of last modified.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateLastModified()
|
||||
{
|
||||
// @see http://stackoverflow.com/questions/2215354/php-date-format-when-inserting-into-datetime-in-mysql
|
||||
$this->update(['last_modified' => get_datetime_string()]);
|
||||
|
||||
return event(new PlayerProfileUpdated($this));
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,5 @@ $factory->define(Player::class, function (Faker\Generator $faker) {
|
||||
'uid' => factory(App\Models\User::class)->create()->uid,
|
||||
'player_name' => $faker->firstName,
|
||||
'tid_skin' => 0,
|
||||
'last_modified' => $faker->dateTime,
|
||||
];
|
||||
});
|
||||
|
@ -30,13 +30,6 @@ class PlayerTest extends TestCase
|
||||
$this->assertNull($player->getJsonProfile(-1));
|
||||
}
|
||||
|
||||
public function testUpdateLastModified()
|
||||
{
|
||||
$player = factory(Player::class)->make();
|
||||
$this->expectsEvents(\App\Events\PlayerProfileUpdated::class);
|
||||
$player->updateLastModified();
|
||||
}
|
||||
|
||||
public function testGetTidSkinAttribute()
|
||||
{
|
||||
$player = factory(Player::class)->create([
|
||||
|
Loading…
Reference in New Issue
Block a user