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
請幫助...
你試過使用'composer dump-autoload'嗎? – fmgonzalez
在你的標籤模型中,在文章方法中,你是指它作爲belongsToMany('App \ Article或App \ Articles? – Birdman
是的,我沒有工作:(@fmgonzalez – Haboosh