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条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效