Use Laravel's built-in updater

This commit is contained in:
Pig Fang 2019-03-02 23:47:51 +08:00
parent 3cf19d8656
commit 5332589b65
5 changed files with 4 additions and 28 deletions

View File

@ -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));

View File

@ -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));

View File

@ -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));
@ -160,7 +160,6 @@ class Player extends Model
{
$this->update([
'player_name' => $newName,
'last_modified' => get_datetime_string(),
]);
$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));
}
}

View File

@ -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,
];
});

View File

@ -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([