/**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $list = TodoList::findOrFail($id);
     //$items = $list->listItems()->get();
     return View::make('todos.show')->withList($list);
     //->withItems($items);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store($list_id)
 {
     $todo_list = TodoList::findOrFail($list_id);
     // define rules
     $rules = array('content' => array('required'));
     // pass input to validator
     $validator = Validator::make(Input::all(), $rules);
     // test if input fails
     if ($validator->fails()) {
         return Redirect::route('todos.items.create', $list_id)->withErrors($validator)->withInput();
     }
     $item = new TodoItem();
     $item->content = Input::get('content');
     $todo_list->listItems()->save($item);
     return Redirect::route('todos.show', $todo_list->id)->withMessage('Item was added!');
 }
Beispiel #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store($list_id)
 {
     $todo_list = TodoList::findOrFail($list_id);
     //Define rules for validation
     $rules = array('content' => ['required', 'unique:todo_items', 'string']);
     // pass rules and input to validator class
     $validator = Validator::make(Input::all(), $rules);
     // test if input fails
     if ($validator->fails()) {
         // $messages = $validator->messages();
         // return $messages;
         return Redirect::route('todos.items.create', $list_id)->withErrors($validator)->withInput();
     }
     $content = Input::get('content');
     $item = new TodoItem();
     $item->content = $content;
     $item->user_id = Auth::user()->id;
     $todo_list->listItems()->save($item);
     return Redirect::route('todos.show', $todo_list->id)->withMessage('Task was created! ');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $todo_list = TodoList::findOrFail($id)->delete();
     return Redirect::route('todos.index')->withMessage('Item deleted!');
 }
Beispiel #5
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     // $list =
     $list = TodoList::findOrFail($id);
     if ($list->user_id == Auth::user()->id) {
         $list->delete();
         return Redirect::route('todos.index')->withMessage("List was deleted.");
     } else {
         return Redirect::route('todos.index')->withMessage('You are not authorised to destroy this list.');
     }
 }