Laravel 5:Container.php第734行中的ReflectionException:类任务不存在错误

时间:2017-07-14 10:50:16

标签: php laravel-5.2

我是laravel的新手,我遇到了这个问题。我正在尝试创建一个任务列表,用户可以在其中创建,编辑和删除任务。 我在尝试编辑任务时发生错误。当我点击"编辑"按钮,显示:

ReflectionException in Container.php line 734:
Class Task does not exist
in Container.php line 734
at ReflectionClass->__construct('Task') in Container.php line 734
at Container->build('Task', array()) in Container.php line 629
at Container->make('Task', array()) in Application.php line 697
at Application->make('Task') in Router.php line 993

这是我的控制器类:

TasksController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use Input;
use Redirect;
use App\Task;

class TasksController extends Controller
{
    public function home()
    {
        $tasks = Task::all();

        return view('home', compact('tasks'));
    }

    public function create()
    {
        return view('create');
    }

    public function edit(Task $task)
    {
        return view('edit', compact('task'));
    }

    public function delete()
    {
        return view('delete');
    }

    public function saveCreate()
    {
        $input = Input::all();

        $task = new Task;
        $task->title = $input['title'];
        $task->body = $input['body'];
        $task->save();

        return Redirect::action('TasksController@home');
    }

    public function doEdit()
    {
        $task = Task::findOrFail(Input::get('id'));
        $task->title = Input::get('title');
        $task->body = Input::get('body');
        $task->done = Input::get('done');
        $task->save();

        return Redirect::action('TasksController@home');
    }
}

这是我的路线档案:

<?php
Route::model('task', 'Task');
Route::get('/', 'TasksController@home');
Route::get('/create', 'TasksController@create');
Route::get('/edit/{task}', 'TasksController@edit');
Route::get('/delete', 'TasksController@delete');

Route::post('/create', 'TasksController@saveCreate');
Route::post('/edit', 'TasksController@doEdit');
?>

Home.blade.php文件

@extends('layout')
@section('content')
<section class="header section-padding">
  <div class="background">&nbsp;</div>
  <div class="container">
    <div class="header-text">
      <h1>Learning Laravel: The Easiest Way</h1>
      <p>
        Fastest way to learn developing web applicatios <br> using Laravel 5 framework.
      </p>
    </div>
  </div>
</section>

<div class="container">
  <section class="section-padding">
    <div class="jumbotron text-center">
      <div class="panel panel-default">
        <div class="panel-heading">
          <h1>
            <span class="grey">Our</span> To-do List
          </h1>
        </div>

        @if($tasks->isEmpty())
          <p> Currently, there is no task! </p>
        @else
          <table class="table table-bordered">
            <thead>
              <tr>
                <th>#</th>
                <th>Title</th>
                <th>Body</th>
                <th>Finish</th>
                <th>Action</th>
              </tr>
            </thead>
            <tbody>
              @foreach($tasks as $task)
                <tr>
                  <td>{{ $task->id }}</td>
                  <td>{{ $task->title }}</td>
                  <td>{{ $task->body }}</td>
                  <td>{{ $task->done ? 'Yes' : 'No' }}</td>
                  <td>
                    <a href="{{ action('TasksController@edit', $task->id) }}" class="btn btn-info">Edit</a>

                    <a href="{{ action('TasksController@delete', $task->id) }}" class="btn btn-info">Delete</a>
                  </td>
                </tr>
              @endforeach
            </tbody>
          </table>
        @endif
      </div>
    </div>
  </section>
</div>

<script>
  $(function(){
    $("#home").addClass('active');
  });
</script>
@stop

和edit.blade.php文件

@extends('layout')
@section('content')
<section class="header section-padding">
  <div class="background">&nbsp;</div>
  <div class="container">
    <div class="header-text">
      <h1>Edit</h1>
      <p>Edit tasks page</p>
    </div>
  </div>
</section>

<div class="container">
  <section class="section-padding">
    <div class="jumbotron text-center">

      {{ Form::open(['url' => '/edit', 'class' => 'form']) }}
      {{ Form::hidden('id' => $task->id) }}
      <fieldset>
        <legend>Edit Task {{ $task->id }}</legend>

        <!-- Task Title -->
        <div class="form-group">
          {{ Form::label('title', 'Title') }}
          {{ Form::text('title', $task->title, ['class' => 'form-control']) }}
        </div>

        <!-- Task Body -->
        <div class="form-group">
          {{ Form::label('body', 'Body') }}
          {{ Form::text('body', $task->body, ['class' => 'form-control']) }}
        </div>

        <!-- Task Done -->
        <div class="form-group">
          {{ Form::label('done', 'Done') }}
          {{ Form::checkbox('done', 1, $task->done, ['class' => 'checkbox']) }}
        </div>

        <!-- Save Button -->
        <div class="form-group">
          {{ Form::submit('Save Task', ['class' => 'btn btn-primary']) }}
        </div>
      </fieldset>
      {{ Form::close() }}
    </div>
  </section>
</div>

<script type="text/javascript">
  $(function(){
    $("#about").addClass('active');
  });
</script>
@stop

0 个答案:

没有答案