public function action_index() { //初期表示 $view = View::forge('login/index'); //既にログインしてたら、home画面へリダイレクト AUth::check() and Response::redirect('home'); //エラー文のセット $error = null; //認証インスタンスの生成 $auth = Auth::instance(); //入力項目の取得 if (Input::post()) { //DBとの比較 if ($auth->login(Input::post('username'), Input::post('password'))) { //ログインするユーザのグループが1(学生)の場合 if (Auth::member(1)) { //学生用home画面にリダイレクト Response::redirect('home'); } else { if (Auth::member(100)) { //管理者用home画面にリダイレクト Response::redirect('admin'); } } } else { $error = 'ユーザ名かパスワードに誤りがあります。'; $view = View::forge('login/index'); $view->set('error', $error); } } return $view; }
public function post(Request $request) { if (Auth::user()) { $rules = ['article_id' => 'required|integer', 'parent_id' => 'required|integer', 'content' => 'required|max:255']; $data = ['article_id' => $request->input('articleId'), 'parent_id' => $request->input('parent_id'), 'content' => $request->input('comment')]; if (validate::make($data, $rules)) { $model = new Comment($data); $model->author = Auth::user()->name; $model->user_id = AUth::user()->id; if ($model->save()) { return redirect()->back()->with('success', 'comment succeed'); } else { return redirect()->back()->with('error', 'something wrong occurred,please fill in again')->withInput(); } } else { } } else { return redirect()->back()->with('error', "you haven't logged in yet")->withInput(); } }