I am learning Laravel by doing a self-exercise. Basically what I want to achieve is the parameter 'id' can be passed to the Controller from Route to get a list of different topics for that specific id when the link is clicked. I have checked all other posts and seems I can't get the answer there.
Here is my code in Route.php where mainpage is the index page of my application.
Route::get('/public/', array( 'as' => 'Personal_assistant' , 'uses' => 'category_by_user@get_mainpage'));
Route::get('public/{id}' , array( 'as' => 'viewtopic' , 'uses' => 'category_by_user@get_topic'));
My 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);
}
}
My 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>
Error detail log as follows:
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
Thanks so much in advanced for any help out there.
Can you show the links and the code that passes in your links the id? Maybe the $id is not passed correctly in your href attr.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.