SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use App\Todo;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\Validator;
  8.  
  9. class TodoController extends Controller
  10. {
  11.     public function __construct() {
  12.         $this->middleware("web");
  13.     }
  14.  
  15.     public function show() {
  16.        
  17.         return view("layout")->with("todos", Todo::all());
  18.     }
  19.  
  20.     public function create(Request $request) {
  21.  
  22.         $validate = Validator::make($request->all(), [
  23.             "todo_title" => "required|min:5",
  24.             "todo_desc" => "required|min:10"
  25.         ]);
  26.  
  27.         if($validate->fails()) {
  28.             return redirect()->back()->withInput()->withErrors($validator);
  29.         }
  30.  
  31.         $todo = new Todo();
  32.        
  33.         $todo->title = $request->todo_title;
  34.         $todo->desc = $request->todo_desc;
  35.  
  36.         $todo->save();
  37.  
  38.         return redirect("/");
  39.     }
  40.  
  41.     public function edit(Request $request, $id) {
  42.  
  43.         $todoItem = Todo::findOrFail($id);
  44.  
  45.         $validate = Validator::make($request->all(), [
  46.             "todo_title" => "required|min:5",
  47.             "todo_desc" => "required|min:10"
  48.         ]);
  49.  
  50.         if($validate->fails()) {
  51.             return redirect()->back()->withInput()->withErrors($validator);
  52.         }
  53.  
  54.         $todo->title = $request->todo_title;
  55.         $todo->desc = $request->todo_desc;
  56.  
  57.         $todo->save();
  58.  
  59.         $request->session()->flash("notification", "Todo edited successfully");
  60.         $request->session()->flash("notification_type", "success");
  61.  
  62.         return redirect("/");
  63.     }
  64.  
  65.     public function delete(Request $request) {
  66.         $todoItem = Todo::findOrFail($request->todoId);
  67.         $todoItem->delete();
  68.         $request->session()->flash("deleted", "Todo deleted successfully");
  69.         return redirect("/");
  70.     }
  71. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top