duankuang7928 2017-11-30 15:10
浏览 30
已采纳

动作未定义laravel / php控制器

I am having a problem with a controller action in a laravel project and I have no idea why, since everything seems fine.

Heres my route concerning the error part:

Route::get('/reminds','RemindController@index');
Route::get('/reminds','RemindController@create');

Heres the create and index method that are defined in the RemindController.php file:

    public function index()
{
    $reminds  = Remind::all();
    return View::make('remind.index', compact('reminds'));
}



public function create()
{
    try {


        $listyears = RemindController::generate_list(date('Y')-100, 101);
        $listmonths = RemindController::generate_list(1, 12);
        $listdays = RemindController::generate_list(1, 31);

        return View::make('remind.create', compact('listyears', 'listmonths', 'listdays'));
    } catch (Exception $e){
        App:abort(404);
    }
}

In create.blade.php(of remind view) I have this that calls the problematic index:

    <div class="panel-heading">
    <h2>create reminder</h2>
</div>
<div class="panel-body">
    {!! Form::open(['action'=> 'RemindController@index', 'class' => 'form']) !!}

The problem is that each time I try to access the page that calls the reminder creation form I get error:

ErrorException (E_ERROR)
Action App\Http\Controllers\RemindController@index not defined. (View: C:\Users\myusername\Desktop\project\prototypeesources\viewsemind\create.blade.php)

However I clearly defined it. I dont understand. Thank you

  • 写回答

3条回答 默认 最新

  • dsiimyoc804955 2017-11-30 15:13
    关注

    Route::get('/reminds','RemindController@index'); Route::get('/reminds','RemindController@create');

    this is the same route, so technically on this part you have an issue already. try to change the HTTP protocol or rename your route instead.

    Route::get('reminds','RemindController@index');
    Route::post('reminds','RemindController@create');
    

    or

    Route::get('reminds','RemindController@index');
    Route::get('reminds/create','RemindController@create');
    

    also omit the first slash on your route already, there's no use of doing that.

    --- update*

    instead of using the static call Route

    you may use something like this

    $router->group(function(){
       $this->get('/',['as' => "homepage" , 'use' => "MainController@homepage"] );
    
       $this->group(['prefix' => "dashboard",'as' => "dashboard"],function(){
          $this->get('/',['as' => "index",'use' => "DashboardController@index"]);
    });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?