/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(Request $request) { if ($request->query('list_id') !== NULL) { $list = TodoList::find($request->query('list_id')); $tasks = $list->tasks; } else { $tasks = Task::get(); } return response()->json($tasks); }
public function delete(Request $request, Task $task) { $this->authorize('store', $task); $listID = $task->todo_list_id; $task->delete(); $lastPage = \App\TodoList::find($listID)->tasks()->paginate(config('pagination.per_page'))->lastPage(); //last possible page $page = $request->get('page'); //current page $page = $page <= $lastPage ? $page : $lastPage; //calculate the possible page return redirect('/lists/' . $listID . '?page=' . $page)->with('info', 'The task has been deleted successfully'); }
/** * 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' => array('required')); //pass input to rules using validarot class $validator = Validator::make(Input::all(), $rules); //test validity 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!'); }
/** * Store a newly created resource in storage. * * @param Request $request * @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 is valid if ($validator->fails()) { return redirect()->route('todos.items.create', $list_id)->withErrors($validator)->withInput(); } $item = new \App\TodoItem(); $item->content = Input::get('content'); $todo_list->listItems()->save($item); return redirect()->route('todos.show', $todo_list->id)->withMessage('Items was added'); }
/** * Bootstrap any application services. * * @return void */ public function boot() { view()->composer('layouts.app', function ($view) { if (!auth()->user()) { return; } $userId = auth()->user()->id; //user can be retrieved only after the middleware is called $lists = TodoList::where('user_id', $userId)->get(); $view->with('lists', $lists); }); if (config('database.default') == 'sqlite') { $db = app()->make('db'); $db->connection()->getPdo()->exec("pragma foreign_keys=1"); } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store($listId, Request $request) { $list = TodoList::findOrFail($listId); $task = new Task(); $task->name = $request->get('name'); $task->description = $request->get('description'); $task->chick = true ? $request->get('chick') == 'true' : false; $task = $list->tasks()->save($task); // $task->save(); // $task = new Task([ // 'name' => $request->get('name'), // 'description' => $request->get('due'), // 'todolist_id'=>1, // 'chick' => true ? $request->get('done') == 'true' : false // ]); // $task = $list->tasks()->save($task); return \Redirect::route('list.show', $listId)->with('message', 'Your task has been 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'); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $todoLists = TodoList::all(); return view('TodoList', ['todoLists' => $todoLists, 'title' => 'TodoList']); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $todo_list = \App\TodoList::findOrFail($id)->delete(); return redirect()->route('todos.index')->withMessage('List was deleted'); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $list = TodoList::findOrFail($id); $items = $list->listItems()->get(); return View::make('todos.show')->withList($list)->withItems($items); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $list = TodoList::find($id); $list->delete(); return response('', 204); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $todo_lists = \App\TodoList::all(); return view('todos.index')->with("todo_lists", $todo_lists); }
/** * 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('List successfully deleted!'); }