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

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP