php - Laravel 中的表单操作

标签 php laravel laravel-4 php-5.3 laravel-routing

我的 Laravel 表单有问题, 所以我的项目结构是:

controllers/
       administration/
            NewsController.php

在 NewsController 中我有一个方法调用:postCreate():

 public function postCreate(){
    $validator = Validator::make(Input::all(), \News::$rules);
    if($validator->passes()){
        $news = new \News();
        $news->title = Input::get('title');
        $news->content = Input::get('content');
        $news->author = Input::get('author');
        $news->type = Input::get('type');

        $image = Input::file('file');
        $filename = time().".".$image->getClientOriginalExtension();
        $path = public_path('content/images/' . $filename);
        Image::make($image->getRealPath())->resize(468,249)->save($path);
        $news->image = 'content/images/'.$filename;
        $news->save();

        return Redirect::to('/administration/news/add')
            ->with('message','Succes');
    }
    return Redirect::to('/administration/news/add')
        ->with('message','Error')
        ->withErrors($validator)
        ->withInput();
}

我的表单有操作:

{{ Form::open(array('url'=>'administration/news/create', 'files'=>true)) }}
{{ Form::close() }}

我的路线:

Route::post('/administration/news/create', array('uses'=>'App\Controllers\Administration \NewsController@postCreate'));

但是当我提交时出现错误:

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException

我不明白我的问题出在哪里。

最佳答案

一个小调整......忘记手动创建地址。

在routes.php中:

Route::post('/administration/news/create', 
          array('uses'=>'App\Controllers\Administration\NewsController@postCreate',
                 'as' => 'news.post.create'));

查看中:

{{ Form::open(array('url'=>route('news.post.create'), 'files'=>true)) }}

无需记住任何这些地址。

关于php - Laravel 中的表单操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26887102/

相关文章:

laravel - laravel 中的迁移是什么

mysql - Laravel wherebetween with orwherebetween

php - 模型中的 Laravel 4 bool 值

php - 使用 Paypal-Php-SDK 创建发票失败并出现 "Can not deserialize instance of java..."错误

php - 带有随机添加其他图像区域的图像

php - 无法验证来自mysql数据库的数据

php - Laragon 400 错误请求 Laravel 5.1

php - Laravel 5 多个下载文件

php - ExtJS 4 - 从超链接加载网格

php - 使用按钮将数据从一个表移动到另一个表 Laravel