类App \文章未找到

时间:2016-03-21 19:43:50

标签: php laravel

我使用的是Laravel 5.2,我从"文章"重新命名了我的模型。到"文章"。我为班级和控制器做了同样的事情,但我在" show"在我的控制器中的方法。

  

Container.php第738行中的ReflectionException:

这是我的控制器:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Requests\ArticleRequest;
use App\Http\Controllers\Controller;
use App\Article;
use App\User;
use App\Tag;
use Auth;

class ArticlesController extends Controller
{

public function __construct()
{
    $this->middleware('auth');
}

public function index()
{
    $articles = article::latest('created_at')->get();

    return view('articles.home', compact('articles'));
}

public function show(Article $article)
{
    return view('articles.show', compact('article'));
}

public function create()
{
    $tag = Tag::lists('name', 'id');

    return view('articles.create', compact('tag'));
}

public function store(ArticleRequest $request)
{
    $article = Auth::user()->article()->create($request->all());

    $article->tags()->attach($request->input('tags'));

    flash('Your Article Has Been Successfully Saved','Good Job');

    return redirect('articles');
}

public function edit(Article $articles)
{
    return view('articles.edit', compact('articles'));
}

public function update(Article $articles, ArticleRequest $request)
{
    $articles->update($request->all());

    return redirect('articles');
}

}

这是我的模特:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Article extends Model
{
    protected $table = "articles";

    protected $fillable = [
        'title',
        'body',
        'published_at',
        'user_id'
    ];

    public function user()
    {
        return $this->belongsTo('App\User');
    }

    public function tags()
    {
        return $this->belongsToMany('App\Tag')->withTimestamps();
    }
}

这是注册的路线:

 Route::resource('articles','ArticlesController');

终于来了我的show.blade.php:

@extends('app')

@section('content')

<h2>{{ $article->title }}</h2>

<div class="body">
    <p>{{ $article->body }}</p>
</div>

@stop

1 个答案:

答案 0 :(得分:6)

如果您使用显式路由模型绑定,是否使用新类名更新RouteServiceProvider

如果您没有使用显式绑定,则您的路由为articles且您的模型为Article,因此Laravel无法再隐式绑定它。将路线更改为Route::resource('article'),它应该有效。