그래서 저는 현재 Laravel의 브라우저 게임을 만들고 있습니다. 지금까지는 프레임 워크를 좋아하지만 경험이별로 없으며이 기능을 사용할 수 없습니다.laravel의 멋진 생성자에서 저장
기본적으로 나는 모든 사용자가 instantieted 될 때마다 업데이트하고 있는데, 사용하지 않을 때 업데이트 할 이유가 없기 때문입니다. 그러나 생성자에서이 함수를 호출하면 사용자가 업데이트되지 않고 생성자 외부에서 함수를 호출 할 때만 작동합니다.
내가 놓친 적이 있습니까?
미리 감사드립니다.
<?php
class User extends Eloquent implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password', 'remember_token');
public function __construct($arguments = array())
{
parent::__construct($arguments);
$this->updateHp();
}
public function updateHp()
{
$this->hp_last = time();
$this->save();
}
}
그러나 먼저 부모 생성자에서 페치 된 것은 아닌가? – TrickyInt
Eloquent는 정적 클래스이며 데이터를 쿼리 (find, first, get)에서 가져오고 모델을 만들 때 빈 모델 만 있고 데이터가 없습니다. –
모델을 만드는 예제를 보여주기 위해 편집되었습니다. –