将路由绑定到错误的方法控制器

时间:2017-03-31 09:00:04

标签: php laravel laravel-5 laravel-5.1

我正在使用laravel 5.1 app。一世 有以下路线:

Route::get('{thing}', 'DisplayController@showThingNewRoute');
Route::get('{about}', 'DisplayController@showAboutNewRoute');

我也像这样使用RouteServiceProvider:

    public function boot(Router $router)
    {

    parent::boot($router);

    $router->bind('thing', function($thing){ 
       return \App\Thing::publish()->where('seo_url', '=', $thing)->first(); 
   }); 

    $router->bind('about', function($about){ 
       return \App\About::publish()->where('seo_url', '=', $about)->firstOrFail(); 
    });    

    }

问题在于我无法使用第二种方法showAboutNewRoute

执行路线

我在这里做错了什么?

2 个答案:

答案 0 :(得分:2)

你的两条路线共享相同的网址,无论你在花括号里面放什么它就像一个变量。

您可以像这样定义路线

Route::get('thing/{thing}', 'DisplayController@showThingNewRoute');
Route::get('about/{about}', 'DisplayController@showAboutNewRoute');

否则无论你将在你的域之后放置什么,它都会选择第一条路径,除非你将任何字符串定义为get方法的第一个参数。

答案 1 :(得分:0)

您的路由具有相同的URL,访问条件相同。对于laravel,如果在根URL旁边放置一个字符串,则可以访问这两个路径。

您需要消除这样的路线歧义,例如:

op1=$(top -bn1 | grep "Cpu(s)" | awk '{print$2}' | sed -e 's/%us,//g')
op2=$(top -bn1 | grep "load average" | awk '{print$12}' |sed -e 's/,//g')
val2=${op2%.*}
val1=${op1%.*}
echo $val1
echo $val2

if [ val1 > 50 ] || [ val2 > 50 ] ; then

  echo -e "CPU Percentage on $HOSTNAME is  $op1  and Current  Load is  $op2  Which are higher than 50% usage. Kindly Login to $HOSTNAME and examine  the process. If apache process consume the more space kindly execute the following command to restart all the SWLB's. \n\n Host Name    : $HOSTNAME   \n User ID          : inauat \n Path              :/inautilus/xjp/ers/servers \n Script Name : apache_all.sh  \n\n Note: If the SWLB restart doesn't resolve the problem, contact Unix support  to investigate further. "| mutt -s " $HOSTNAME CPU Status Alert  " "test@testdomain.com" -c "test@testdomain@inautix.co.in"

else
    echo  'CPU load appears normal.'
fi