コード例 #1
0
 public function login()
 {
     if (Input::get('login')) {
         $rules = array('email' => 'required', 'password' => 'required|min:3|alphaNum');
         $validator = Validator::make(Input::all(), $rules);
         if ($validator->fails()) {
             return back()->withInput()->withErrors($validator);
         } else {
             $email = Input::get('email');
             $password = Input::get('password');
             $user = User::where('email', '=', $email)->where('password', '=', $password)->first();
             if ($user != NULL) {
                 $blogs = Blog::orderby('created_at', 'dec')->Paginate(10);
                 $blogs->setPath('blogs');
                 Session::put('user', $user);
                 //return View::make('showblogs')->with('user',$user)->with('blogs',$blogs);
                 return Redirect::to('/');
             } else {
                 Session::flash('message', 'Incorrect email or paswword');
                 return back()->withInput();
             }
         }
     } else {
         if (Session::has('user')) {
             return Redirect::to('/');
         } else {
             return View::make('login');
         }
     }
 }
コード例 #2
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $blog = Blog::find($id);
     $blog->delete();
     Session::flash('message', 'Successfully deleted the blog!');
     return Redirect::to('blogs');
     //
 }