如何解决此错误:在laravel中找不到控制器方法?

时间:2017-05-10 03:35:53

标签: laravel

Controller.php第269行中的NotFoundHttpException:找不到控制器方法。

提交表单前的原件:http://localhost/framework_freshway/public_html/home/setting

soulfy / setting.blade.php

   <li>
                                <form action="../home/setting" method="post">
                                <span class="setting-name">MENU CSS</span>
                                <!-- <form method="POST" action="/posts"> -->
                                {{ csrf_field() }}  
                                <span class="setting-value center"> 
                                <select name="cars">
                                    <option value="red">Red</option>
                                    <option value="blue">Green</option>
                                    <option value="green">Orange</option>
                                    <option value="orange">Yellow</option>
                                    <option value="orange">Blue</option>
                                    <option value="orange">Black</option>
                                    <option value="orange">White</option>
                                    <option value="orange">Grey</option>
                                </select>
                                <!-- <div style="width: 150px; height: 30px;">        <input type="image" src="http://localhost/framework_freshway/public_html/images/submit.png" value="SUBMIT" width="10"> -->
                                <input type="submit" value="Submit"> 
                                </span>                                         
                                <br><br><br>    

                                </form>

                            </li>   

按下提交按钮后,它会转到此网址:

http://localhost/framework_freshway/public_html/home/setting

Controller.php第269行中的NotFoundHttpException:找不到控制器方法。

Route::post('/', [
'uses' => 'SettingController@getMenu'
]);

Route::controllers([
 'auth' => 'Auth\AuthController',
 'password' => 'Auth\PasswordController',
 'home'=>'HomeController',
 'member'=>'MemberController',
 'mail'=>'MailController',
 'social'=>'SocialController',
 'ajax'=>'AjaxController',
 'api'=>'ApiController',
 'timeline'=>'TimelineController',
 'setting'=>'SettingController',
 'ecommerce'=>'EcommerceController',
 'test'=>'TestController',
]);

2 个答案:

答案 0 :(得分:0)

看起来您的服务器运行的级别要高一些。

在应用的根目录中启动您的服务器

路线应为http://localhost/home/setting

home/setting将是您的web.php路由文件中匹配的路由。

因此,在该路线文件中,您需要一条像Route::post('home/setting', <controller@method> )

这样的路线

https://laravel.com/docs/5.3/routing#basic-routing 了解更多信息

HTH

答案 1 :(得分:0)

您的表单操作应如下所示: -

<form action="{{ url('/home/setting') }}" method="post">
                   or
<form action="{{ action('SettingController@getMenu')}}" method="post">

尝试这条路线: -

Route::post('/home/setting', 'SettingController@getMenu');

希望它有所帮助!