在类控制器中找不到方法:BadMethodCallException

时间:2019-03-20 09:49:54

标签: laravel-5.7

我正在学习laravel。我只想动态显示来自我的mysql表的链接,不知道我的错误来自哪里。我有这个错误:

  

BadMethodCallException方法App \ Http \ Controllers \ NiceActionController :: getHome不存在。

控制器 app\Http\Controllers\NiceActionController.php

namespace App\Http\Controllers;

use \Illuminate\Http\Request;
use App\NiceAction;

    class NiceActionController extends Controller
    {
        public function getHome()
        {
            $actions = NiceAction::all();
            return view('home',['actions'=>$actions]);
        }
    }
路由文件中的

routes\web.php

Route::group(['middleware'=>['web']],function(){
    Route::get('/',[
        'uses'=>'NiceActionController@getHome',
        'as'=>'home'
    ]);

Route::group(['prefix' => 'do'], function () {

    Route::get('/{action}/{name?}', [
        'uses'=>'NiceActionController@getNiceAction',
        'as' =>'niceaction'
    ]);
});

});

并在视图中:

views\home.blade.php

@foreach ($actions as $action)
            <a href="{{ route('niceaction',['action'=>lcfirst($action->name)])}}">
                {{$action->name}}
              </a>
            @endforeach

我有模特,但暂时没有

app\NiceAction.php

namespace App;

use Illuminate\Database\Eloquent\Model;

class NiceAction extends Model
{
    //
}

感谢您的帮助

0 个答案:

没有答案