2016-03-21 149 views
4

所以,我使用laravel 5.2,並將我的模型從「文章」更名爲「文章」,我對班級以及控制器做了同樣的處理..但是我有錯誤在我的控制器 「秀」 的方法..Class App Articles not found

「在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 

請幫助...

+0

你試過使用'composer dump-autoload'嗎? – fmgonzalez

+0

在你的標籤模型中,在文章方法中,你是指它作爲belongsToMany('App \ Article或App \ Articles? – Birdman

+0

是的,我沒有工作:(@fmgonzalez – Haboosh

回答

6

如果您使用顯式路由模型綁定,你是否更新RouteServiceProvider與新的類名?

如果你不使用顯式綁定,你的路由是articles,你的模型是Article,所以Laravel不能夠隱式綁定它。改變路線到Route::resource('article')它應該工作。