2017-03-07 59 views
0

我知道這可能是一件非常愚蠢的事情,但我似乎無法修復它。Handler.php中的NotFoundHttpException行131:

我得到這個錯誤

NotFoundHttpException在Handler.php行131:沒有找到模型查詢結果[應用程序\模塊\菜單\型號\菜單。

而且似乎無法解決它。目前它甚至不應該要求菜單模型。

這裏是我的route.php

Route::get('/signup', [ 
    'uses' => '[email protected]', 
    'as' => 'signup' 
]); 

這裏是我的OpenController.php

<?php 

namespace App\Modules\Open\Http\Controllers; 

use Illuminate\Http\Request; 

use App\Http\Requests; 
use App\Http\Controllers\Controller; 

use App\Modules\Menus\Models\Menu; 
use App\Modules\Authors\Models\Story; 

class OpenController extends Controller 
{ 
    public function index(){ 
     $menus_child = Menu::where('menu_id', 0)->with('menusP')->get(); 
     $menu = Menu::where('id', 1)->orWhere('title', 'home')->firstOrFail(); 
     return view('open::index', compact('menus_child', 'menu')); 
    } 

    public function content($id){ 
     $menus_child = Menu::where('menu_id', 0)->with('menusP')->get(); 
     $menu = Menu::where('id', $id)->firstOrFail(); 
     $layout = $menu->type; 
     $stories = Story::where('type', 'public')->get(); 

     return view('open::public/'.$layout, compact('menus_child', 'menu', 'stories')); 
    } 

    public function signup(){ 
     echo "sign up"; 
     die(); 
    } 
} 

這裏是我的signup.blade.php

@extends('templates::layouts.public') 
@section('content') 
    <h1>signup blade</h1> 
@stop 

這裏是我的公衆。 blade.php版面

<!DOCTYPE html> 
<html> 
    <head> 
     <title>Website</title> 
     <meta name="viewport" content="width=device-width, initial-scale=1"> 
     <link href="https://fonts.googleapis.com/css?family=Cherry+Swash|Crafty+Girls|Homemade+Apple|Italianno|Parisienne|Ranga|Rochester" rel="stylesheet"> 
     <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet"> 
     {!! Html::style('css/bootstrap.min.css') !!} 
     {!! Html::style('css/style.css') !!} 
     {!! Html::script('js/jquery-3.1.1.min.js') !!} 
     {!! Html::script('js/bootstrap.min.js') !!} 
     {!! Html::script('js/main.js') !!} 
    </head> 
    <body> 
     <div class="container"> 
      <div id="main"> 
       <div id="header"> 
        <div id="logo"> 
         <div class="row"> 
          <div class="col-lg-6"> 
           <h1>Website</h1> 
          </div> 
          <div class="col-lg-6"> 
           <div class="slogan"> 
            {!! Html::link('/signup', 'Signup') !!}/{!! Html::link('/login', 'Login') !!} 
           </div> 
          </div> 
         </div> 
        </div> 
        @include('menus::menu') 
       </div> 
       <div id="site_content"> 
        <div id="content"> 
         @yield('content') 
        </div> 
       </div> 
      </div> 
     </div> 
    </body> 
</html> 

這是我menu.blade.php

<div id="menubar"> 
    <ul class="nav navbar-nav" id="menu"> 
     @foreach($menus_child as $grandfather) 
      @if($grandfather->menu_id) 
       <li> 
      @elseif($grandfather->title == 'Home') 
       <li class="parent {{ menu_active([$grandfather->id]) }}"> 
      @elseif(count($grandfather->menusP()->where('menu_id', '>', 0)->get())) 
       <li class="dropdown {{ menu_active([$grandfather->id]) }}"> 
      @else 
       <li class="parent {{ menu_active([$grandfather->id]) }}"> 
      @endif 

      @if(count($grandfather->menusP()->where('menu_id', '>', 0)->get())) 
       {!! HTML::decode(HTML::link($grandfather->id, $grandfather->title.'<span class="caret"></span>', array('class' => 'dropdown-toggle')))!!} 
      @else 
       {!! HTML::link($grandfather->id, $grandfather->title) !!} 
      @endif 

      @if(count($grandfather->menusP)) 
       <ul class="dropdown_menu"> 
        @foreach($grandfather->menusP as $father) 
         @if($father->menu_id) 
          <li class="parent_child"> 
         @else 
          <li> 
         @endif 

         {!! HTML::link($father->id, $father->title) !!} 
        @endforeach 
       </ul> 
      @endif 
     @endforeach 
    </ul> 
</div> 

回答

4

我發現是什麼原因造成的問題。這是我放置路線的方式。所以,我所做的只是把我的註冊路線路線我的頂部和解決我的問題

+0

這解決了我的問題,但是你知道爲什麼嗎? – Gus

+0

@Gus - 我不確定。我只是亂搞,但如果你確實知道爲什麼我會很感激,如果你讓我知道,因爲我很困惑,爲什麼它發生了 – Isis

0

@Gus,@Isis

這篇文章幫我解決一個非常類似(或可能相同)的問題。在我的具體情況,我立刻意識到這是簡單的用戶錯誤 - 這可能有助於解釋爲什麼這可能發生......

考慮前往以下網址,給後續的路線:

GET app.com /團隊/添加喜愛的

[衰] 路線:

// Bad Routing Logic 
Route::get('/team/{team}', '[email protected]'); 
Route::get('/team/add-favorite', '[email protected]'); 
Route::get('/team/add-favorite/{conference}', '[email protected]'); 

顯然,第二個路徑(/團隊/添加喜愛)將永遠不會被調用因爲它只是路由到/team/{team},並且[team]參數填充值爲「add-favorite」。

我的解決辦法也簡單地重新安排路線的順序,像這樣......

[好] 路線:

// Still not good practice, but works 
Route::get('/team/add-favorite', '[email protected]'); 
Route::get('/team/add-favorite/{conference}', '[email protected]'); 
Route::get('/team/{team}', '[email protected]'); 

這仍然是絕對不是最好的做法,但至少會讓每條路線都能正確解決。

app.com/team/add-favorite現在會匹配第一條路線,而類似應用。com/team/17仍將落入第三條列出的路線,並以適當的ID提交給TeamController。

再說一遍 - 我不建議使用「共享」端點以這種方式進行路由,因爲它肯定會導致問題。即 - 更好的希望是從來沒有一個團隊與ID ='添加喜歡'。極不可能,但你明白了...

希望這會有所幫助!

相關問題