public function store()
{
$input = Input::all();
$validator = User::validate($input);
if(!$validator->passes()) {
$notification['danger'] = 'There were validation errors!';
return Redirect::route('user.create')->withInput()->withErrors($validator)->with('notification', $notification);
}
$input['password'] = Hash::make($input['password']);
$user = $this->user->create($input);
$role = $this->role->find($input['role_id']);
$user->roles()->save($role);
$notification['success'] = "User $user->email sucessfuly created.";
return Redirect::route('user.index')->with('notification', $notification);
}
だから私はアーキテクチャについてたくさん読んできましたが、これが「良い」方法ではないことはわかっていますが、解決策はあまり思いつきません。
これを UserRepository UserFormValidator などの一連のクラスに抽出することは、オーバーエンジニアリングのように聞こえます。特に私の場合、それはかなり小さなプロジェクトであり、数週間しか続かないでしょう。
私がもっと興味を持っているのは、このビジネス ロジックを User モデルに抽出する方法です。関係を介して他のモデルを関連付けることは、私の意見では、とにかくモデルの問題です。私の現在のモデル コードは、hasMany()、begsTo() などの関係と、$filleable、$hidden プロパティのみを設定します。
とにかく、私は提案を受け入れています。