简体   繁体   English

多个Laravel 5.5路由方法显示错误

[英]Multiple laravel 5.5 routes methods showing error

I have three routes in web.php 我在web.php中有3条路线

Route::get('/secondary', 'SecondaryController@show');
Route::get('/primary', 'PrimaryController@show');
Route::get('/nursery', 'NurseryController@show');

But when i click on the respective menu link, it presents the first route, others just wont work. 但是,当我单击相应的菜单链接时,它将显示第一个路线,其他路线将无法工作。 pls what am i doing wrongly, i need help. 请问我在做什么错,我需要帮助。 this is code for the controllers for the nursery controller 这是托儿所控制器的控制器代码

public function show($slugs){
     $NurseryPages = NurseryPages::findByURL($slugs);
     return view('nursery.show', ['NurseryPages' =>$NurseryPages]);
}

for the primary controller 对于主控制器

 public function show($slugs){
     $PrimaryPages = PrimaryPages::findByURL($slugs);
     return view('primary.show', ['PrimaryPages' =>$PrimaryPages]);
}

for the secondary controller 用于辅助控制器

public function show($slugs)
{
     $SecondaryPages = SecondaryPages::findByURL($slugs);
     return view('secondary.show', ['SecondaryPages' =>$SecondaryPages]);
}

it will only work well for the nursery section, but on others it displays error: trying to get object of non-property and refers me back to the nursery.show file this is the error msg 它仅适用于托儿所部分,但在其他地方则显示错误:尝试获取非财产对象并将我转回托儿所。显示文件,这是错误消息

 ErrorException (E_ERROR)

Trying to get property of non-object (View: C:\\xampp\\htdocs\\acadapp\\resources\\views\\secondary\\show.blade.php) 尝试获取非对象的属性(视图:C:\\ xampp \\ htdocs \\ acadapp \\ resources \\ views \\ secondary \\ show.blade.php)

    <?php echo $__env->make('inc.secondary.navbar', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

<div class="container">
<div class="row"> 
    <div class="col-md-12">
        <br/><br/><br/>
        <b><h3><?php echo $SecondaryPage->title; ?></b></h3>
             <?php echo $SecondaryPage->body; ?>

        </div>
    </div>
</div>
<?php echo $__env->make('inc.secondary.footer', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

I think you need to change your route like: 我认为您需要更改路线,例如:

Route::get('/secondary/{slug}', 'SecondaryController@show');
Route::get('/primary/{slug}', 'PrimaryController@show');
Route::get('/nursery/{slug}', 'NurseryController@show');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM