未找到控制器方法。 laravel 5.2中的错误

时间:2016-04-28 11:03:36

标签: php controller laravel-5.2

我的控制器文件看起来像这样

<?php

namespace App\Http\Controllers;

use App\Artist;
use App\Song;
use App\Album;

class WebsiteController extends Controller
{


    public function getIndex(){

        return redirect('/');

    }

    public function getHome(){

        $featuredArtist='';
        $featuredAlbum='';
        $featuredSong='';

        return view('website.welcome')->with(array('featuredArtist'=>$featuredArtist,'featuredSong'=>$featuredSong,'featuredAlbum'=>$featuredAlbum));

    }


    public function get_listartist(){

    $artistList = Artist::select('id','artist_name', 'artist_title','artist_image')->get();
    //dd($artistList);
    return view('website.listartist')->with(array('artistList'=>$artistList));
    //skljhkhkl
}

    public function getDonate(){

        return view('website.donate');
    }

    public function getContact(){

        return view('website.contact');
    }
}

我的Route.php看起来像这样

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

Route::get('/', 'WebsiteController@getHome');
Route::controller('site', 'WebsiteController');

除了

之外,大多数链接都在工作

www.domain.com/site/listartist

我收到错误

  

compile.php第9361行中的NotFoundHttpException:控制器方法没有   发现..

任何想法我检查了一切看起来很好

URLOFTheWebSite

谢谢

2 个答案:

答案 0 :(得分:0)

请尝试使用snake-case名称作为方法。我不知道为什么,但camel-case不适用于由两个单词组成的方法。

public function get_some_name() {};  // www.example.com/anything/some-name
public function get_somename() {};  // www.example.com/anything/somename
//it doesn't seem to work with camel-case e.x  getSomename(); www.example.com/anything/somename
public function get_version() {}; //It will also work with camel-case

希望它有所帮助。

答案 1 :(得分:0)

即使这是旧的,它仍然可以帮助新访客。我遇到了同样的错误,发现这是我在web.php中给出的控制器路径错误。

例如: 代替 : 路线:: get('/','WebsiteController @ getHome');

给 路线:: get('/','admin \ WebsiteController @ getHome');