douqianmin5367 2015-01-05 09:38
浏览 469
已采纳

Laravel控制器抛出错误而无法正常工作

I am new in Laravel.

I used way generator to create laravel controller view and model, and it has default values for each item, But when I am going to see that with browser it is not working and showing an Error.

controller (PostsController.php):

class PostsController extends \BaseController {
    public function index()
    {
        $posts = Post::all();

        return View::make('posts.index', compact('posts'));
    }
 }

View (posts/index.blade.php):

This is index view

model (post.php)

class Post extends \Eloquent {

    // Add your validation rules here
    public static $rules = [
        // 'title' => 'required'
    ];

    protected $primarykey='user_id';

    // Don't forget to fill this array
    protected $fillable = [];

}

and this is route:

Route::resource('posts','postsController',array('except'=>array('show')));

when I type localhost:8000/posts/index, Laravel return an error:

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException

What is the problem?

  • 写回答

1条回答 默认 最新

  • dsvtnz6350 2015-01-05 09:43
    关注

    thats becouse you type localhost:8000/posts/index as URL in browser, Just remove index

    localhost:8000/posts

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?