[英]Laravel 5 error when add rules validation on Form Request: ReflectionException in Container.php line 776: Class guest does not exist
[英]ReflectionException in RouteDependencyResolverTrait.php error in creating request validation - Laravel
我的代碼有問題。 我正在遵循Laravel 5中的教程。我正在執行表單驗證,但出現此錯誤,並且我不知道它是如何發生的。 我是Laravel的新手。
我正在創建文章樣本。
這是我的控制器:
<?php namespace App\Http\Controllers;
use App\Article;
use App\Http\Requests;
use App\Http\Controllers\Controller;
//use Illuminate\Http\Request;
use Carbon\Carbon;
//use Request;
class ArticlesController extends Controller {
public function index() {
//$articles = Article::all();
//$articles = Article::latest('published_at')->where('published_at', '<=', Carbon::now())->get();
/** select * from articles where published_at <= now() order by published_at desc */
$articles = Article::latest('published_at')->published()->get();
return view('articles.index', compact('articles'));
}
public function show($id) {
$article = Article::findOrFail($id);
//dd($article->published_at);
return view('articles.show', compact('article'));
}
public function create() {
return view('articles.create');
}
public function store(CreateArticleRequest $request) {
//$input = Request::all();
//$input['published_at'] = Carbon::now();
//$title = Request::get('title');
Article::create($request->all());
return redirect('articles');
}
}
這是我的要求
<?php namespace App\Http\Requests;
use App\Http\Requests\Request;
class CreateArticleRequest extends Request {
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true; //permissions
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'title' => 'required|min:3',
'body' => 'required',
'published_at' => 'required|date'
];
}
}
我的路線:
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', 'WelcomeController@index');
Route::get('home', 'HomeController@index');
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
Route::get('articles','ArticlesController@index');
Route::get('articles/create','ArticlesController@create');
Route::get('articles/{id}','ArticlesController@show');
Route::post('articles','ArticlesController@store');
當我檢查它不允許我插入數據庫中。
因為您使用了錯誤的類,所以拋出了ReflectionException。 您應該在ArticlesController
使用App\\Http\\Requests\\CreateArticleRequest
代替App\\Http\\Requests
您必須將正在使用的CreateArticleRequest包含在使用它的控制器文件中
use Carbon\\Carbon;
后添加此行use Carbon\\Carbon;
use App\\Http\\Requests\\CreateArticleRequest;
它將在控制器中包含您的請求文件
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.