Laravel任务列表教程显示找不到页面

时间:2017-04-10 13:09:16

标签: php laravel

我正在努力学习laravel,所以我开始关注laravel网站上的the tasklist tutorial。页面显示正常,但是当我尝试添加任务时,会转到一个页面,上面写着:“找不到'。

我的代码:

task.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Task extends Model
{
    //
}

Web.php(路线):

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

use App\Task;
use Illuminate\Http\Request;


// Display tasks

Route::get('/', function () {
    $tasks = Task::orderBy('created_at', 'asc')->get();

    return view('tasks', [
        'tasks' => $tasks
    ]);
});

// Add new tasks

Route::post('/task', function (Request $request) {
    $validator = Validator::make($request->all(), [
        'name' => 'required|max:255',
    ]);

    if ($validator->fails()) {
        return redirect('/')
            ->withInput()
            ->withErrors($validator);
    }

    $task = new Task;
    $task->name = $request->name;
    $task->save();

    return redirect('/');
});

//Remove tasks

Route::delete('/task{id}', function ($id) {
    Task::findOrFail($id)->delete();

    return redirect('/');
});

Auth::routes();

Route::get('/home', 'HomeController@index');

我的tasks.blade.php:

@extends('layouts.app')

@section('content')

    <!-- Bootstrap Boilerplate... -->

    <div class="panel-body">
        <!-- Display Validation Errors -->
        @include('common.errors')

        <!-- New Task Form -->
        <form action="/task" method="POST" class="form-horizontal">
            {{ csrf_field() }}

            <!-- Task Name -->
            <div class="form-group">
                <label for="task" class="col-sm-3 control-label">Task</label>

                <div class="col-sm-6">
                    <input type="text" name="name" id="task-name" class="form-control">
                </div>
            </div>

            <!-- Add Task Button -->
            <div class="form-group">
                <div class="col-sm-offset-3 col-sm-6">
                    <button type="submit" class="btn btn-default">
                        <i class="fa fa-plus"></i> Add Task
                    </button>
                </div>
            </div>
        </form>
    </div>

    <!-- Current Tasks -->
    @if (count($tasks) > 0)
        <div class="panel panel-default">
            <div class="panel-heading">
                Current Tasks
            </div>

            <div class="panel-body">
                <table class="table table-striped task-table">

                    <!-- Table Headings -->
                    <thead>
                        <th>Task</th>
                        <th>&nbsp;</th>
                    </thead>

                    <!-- Table Body -->
                    <tbody>
                        @foreach ($tasks as $task)
                        <tr>
                          <!-- Task Name -->
                          <td class="table-text">
                              <div>{{ $task->name }}</div>
                          </td>

                          <!-- Delete Button -->
                          <td>
                              <form action="/task/{{ $task->id }}" method="POST">
                                  {{ csrf_field() }}
                                  {{ method_field('DELETE') }}

                                  <button>Delete Task</button>
                              </form>
                          </td>
                        </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        </div>
    @endif
@endsection

这是我点击“添加任务&#39;:

”时看到的页面

我做错了什么?我使用的是Laravel 5.4

enter image description here

0 个答案:

没有答案