2016-07-27 19 views
0

Ich lerne Laravel durch eine Selbstübung. Grundsätzlich möchte ich erreichen, dass der Parameter 'id' an den Controller von Route übergeben werden kann, um eine Liste verschiedener Themen für diese spezifische ID zu erhalten, wenn auf den Link geklickt wird. Ich habe alle anderen Beiträge überprüft und es scheint, dass ich dort die Antwort nicht bekommen kann.Wie behandelt man Laravel NotFoundHttpException?

Hier ist mein Code in Route.php, wo die Hauptseite die Indexseite meiner Anwendung ist.

Route::get('/public/', array('as' => 'Personal_assistant' , 'uses' => '[email protected]_mainpage')); 
Route::get('public/{id}' , array('as' => 'viewtopic' , 'uses' => '[email protected]_topic')); 

Mein Code in Controller 'category_by_user':

class Category_by_user extends Controller 
{ 
// 

public $restful = true; 

public function get_mainpage() 
{ 

$data = DB::table('categories') 
     -> select('category_name', 'category_description') 
    //->where('category_user_id', '=' , $user_id) 
    ->get(); 

    return view::make('mainpage') 
     ->with('title', 'Category By User') 
     ->with('data' , $data); 
    } 


    public function get_topic($id) 
    { 
     $data1 = DB::table('topics') 
     ->where('Category_id', '=' , $id) 
     ->get(); 


     return View::make('viewtopic') 
     ->with('title', 'All Topic by Category') 
     ->with('data1' , $data1) 
     ->with('id' , $id); 
     } 
} 

Mein Code in viewtopic.blade.php:

{h1>Personal Info Assistant</h1> 

    <!-- will be used to show any messages --> 
    @if (Session::has('message')) 
     <div class="alert alert-info">{{ Session::get('message') }}</div> 
    @endif 

    <table class="table table-striped table-bordered"> 

    <tbody> 
    <!-- // List all categories belongs to that particular user --> 


    @foreach($data1 as $key => $topic) 
     <tr> 

     <td>{{ $topic->topic_description }}</td> 
     <td>ID = {{ $id }}</td> 

     </tr> 
    @endforeach 
    </tbody> 
</table> 

</div> 
</body> 
</html> 

Fehler Detailprotokoll wie folgt:

in RouteCollection.php line 161 
    at RouteCollection->match(object(Request)) in Router.php line 821 
    at Router->findRoute(object(Request)) in Router.php line 691 
    at Router->dispatchToRoute(object(Request)) in Router.php line 675 
    at Router->dispatch(object(Request)) in Kernel.php line 246 
    at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) 
    at call_user_func(object(Closure), object(Request)) in Pipeline.php  line 52 
    at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Debugbar.php line 49 
    at Debugbar->handle(object(Request), object(Closure)) 
    at call_user_func_array(array(object(Debugbar), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136 
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) 
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32 
    at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44 
    at CheckForMaintenanceMode->handle(object(Request), object(Closure)) 
    at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136 
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) 
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32 
    at Pipeline->Illuminate\Routing\{closure}(object(Request)) 
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103 
    at Pipeline->then(object(Closure)) in Kernel.php line 132 
    at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99 
    at Kernel->handle(object(Request)) in index.php line 54 
    at require_once('C:\wamp\www\Personal_Info_App\public\index.php') in server.php line 21 

Vielen Dank für Fortgeschrittene jede Hilfe da draußen.

+0

Soweit ich sehen kann stimmt etwas mit den definierten Routen nicht. Probieren Sie (sicher) '/ public' statt'/public/'und'/public/{id} 'statt' public/{id} '. –

Antwort

0

Können Sie die Links und den Code, der in Ihren Links die ID übergibt? Vielleicht wird die $ ID in Ihrem href attr nicht korrekt übergeben.

+0

Ich glaube nicht, dass die 'id' das Problem ist, da es eine' NotFoundHttpException' ist. Aber es wäre sehr hilfreich für uns, die von ihm angeforderte URL zu sehen. –

+0

! [Hauptseite] (http: //localhost/mainpage.jpg). –

+0

! [Viewtopic] (http: //localhost/viewtopic.jpg). –

Verwandte Themen