<?php namespace App\Http\Controllers; use App\Http\Requests\StoreTodoRequest; use App\Http\Requests\UpdateTodoRequest; use App\Models\Todo; class TodoController extends Controller { /** * Display a listing of the resource. */ public function index() { return view('todo.index', [ 'todos' => Todo::all(), ]); // } /** * Show the form for creating a new resource. */ public function create() { // } /** * Store a newly created resource in storage. */ public function store(StoreTodoRequest $request) { // info($request->all()); // ~/Herd/my-new-site/storage/logs などに出力する。フォームが何を送信しているか確認できる。 Todo::create([ 'user_id' => auth()->id(), 'task' => $request->task, ]); return redirect()->route('todo.index')->with('message.success', 'Todo created successfully!'); // } /** * Display the specified resource. */ public function show(Todo $todo) { // } /** * Show the form for editing the specified resource. */ public function edit(Todo $todo) { // } /** * Update the specified resource in storage. */ public function update(UpdateTodoRequest $request, Todo $todo) { // } /** * Remove the specified resource from storage. */ public function destroy(Todo $todo) { $todo->delete(); return redirect()->route('todo.index')->with('message.success', 'Todo deleted successfully!'); // } }