Actually I'm very new of the php and Laravel5.3,and I have this problem when i want to set request of the form(Doing a simple blog page)
ReflectionException in Route.php line 339: Class App\Http\Controllers\Requests\ArticleRequest does not exist
And this is my controller code(Filename:ArticlesControllers.php):
<?php
namespace App\Http\Controllers;
//namespace App\Http\Controllers;
use App\Http\Requests\ArticleRequest;
use App\Article;
use Carbon\Carbon;
use Illuminate\Http\Request;
class ArticlesControllers extends Controller
{
//
public function index(){
$articles = Article::latest()->get();
//return 'articles';
return view('articles.index')->with('articles',$articles);
}
public function show($id){
$article = Article::find($id);
// if(is_null($article)){
// abort(404);
// }
//dd($artilce);
return view('articles.show',compact('article'));
}
public function create(){
return view('articles.create');
}
public function store(Requests\ArticleRequest $request){
//dd($request->all());
//接受post过来的数据
//存入数据库
//重定向
$input=$request->all();
//$input['published_at']=Carbon::now();
Article::create($input);
return redirect('/articles');
}
}
And the request File code:(Filename:ArticleRequest.php in the path Requests)
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ArticleRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'title'=>'required|min:3',
'content'=>'required',
'published'=>'require'
];
}
}
My Route/Web.php is:
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
//Route::get('/','SiteController@index');
Route::get('/', function () {
return view('welcome');
});
Route::get('/articles','ArticlesControllers@index');
Route::get('/articles/create','ArticlesControllers@create');
Route::get('/articles/{id}','ArticlesControllers@show');
Route::post('/articles/store','ArticlesControllers@store');
How can i get rid of this nasty problem,I've been searching on StackOverFlow but nearly all the answers may not solve it....