ArticleController.php
public function postStore (Request $request)
{
// とてもめんどくさい
$data = $request->all();
// あるいは Input::all();
// とてもめんどくさい
$user = \Auth::user();
Article::create([
'title' => $data['title'],
'body' => $data['body'],
'user_id' => $user->id
]);
}
LazyController.php
class LazyController extends Controller {
var $me;
var $input;
public function __construct()
{
$this->middleware('auth');
$this->me = \Auth::user();
$this->input = Input::all();
}
}
ArticleController.php
class ArticleController extends LazyController {
public function __construct () {
parent::__construct();
// ここに書いてもいいけど
// それはそれでコントローラごとにかかなあかんからめんどくさい
}
public function postStore (Request $request)
{
// らくちん
Article::create([
'title' => $this->input->['title'],
'body' => $this->input->['body'],
'user_id' => $this->me->id
]);
}
}
もっとかっこいい方法あったらおしえてください