0
私はコントローラでこのロジックを持っている:がどのように雄弁であることだろう - Laravel 5.2
// hydratation part 1 (cf son modele)
$matiere->fill($request->all());
// hydratation part 2 with attributes not in the POST
$matiere->id_ecole = Session::get('id_ecole');
$request->has('matiere_inactive') ? $matiere->matiere_inactive = '1' : $matiere->matiere_inactive = null;
if ($matiere->exists) {
$matiere->auteur_modif = Session::get('nom').' '.Session::get('prenom');
} else {
$matiere->auteur_creation = Session::get('nom').' '.Session::get('prenom');
}
私はパート2ではなく、コントローラの、モデルに存在することができることだと思う(私は持っていたいです'brief'コントローラ)。
いいですか?
もしそうなら、どうすればいいですか?
私のモデルは次のとおりです。あなたの提案を
class Matiere extends Model {
protected $table = 'matiere';
protected $primaryKey = 'id_matiere';
protected $fillable = [
'id_matiere',
'code_court_matiere',
'libelle_matiere'
];
public function setCodeCourtMatiereAttribute($value)
{
$this->attributes['code_court_matiere'] = strtoupper($value);
}
public function setLibelleMatiereAttribute($value)
{
$this->attributes['libelle_matiere'] = ucwords($value);
}
}
感謝。そして、すべての読者に幸せな新年。 ドム
私はこの考えに感謝します。しかし、セッションをモデルに直接使用することをお勧めしますか? – Dom