yuzhibiao

553 经验值

    public function store(Request $request)
    {
        //验证规则
        $this->validate($request, [
            'title'        => 'required|min:3',
            'content'      => 'required',
            'published_at' => 'required',
        ]);

        $input = $request::all();
        //下面增加两行,顺便看看$request::get的使用
        $input['intro'] = mb_substr($request::get('content'), 0, 64);
        //$input['published_at'] = Carbon::now();
        Article::create($input);

        return redirect('/articles');
    }

具体代码如上,以为为提示错误:
ErrorException in ValidatesRequests.php line 30:
Argument 1 passed to App\Http\Controllers\Controller::validate() must be an instance of Illuminate\Http\Request, instance of Illuminate\Support\Facades\Request given, called in /Users/yuzhibiao/Code/www.laravel.org/Laravel5-1-20/app/Http/Controllers/ArticlesController.php on line 48 and defined

@JellyBool
恩恩,明白了。那现在就存在问题了,我这个controller是通过php artisan 创建的,默认是:use Illuminate\Http\Request; 我们都要手动改为:use Request;吗?

Laravel提交到ArticlesController@store方法时,使用Request::all();获取表单提交过来的数据报错了。错误如下:

Non-static method Illuminate\Http\Request::all() should not be called statically, assuming $this from incompatible context