0

In my routing if i remove the {page} prefix it works completely fine but when i put it i get an error. For other it is working fine but it is not working for this route: Route::get('/{categories}', 'AdminVisible\CostIncludeController@index'); My AdminPageController:

    public function index($page)
    {
        $page = Page::where('Pages_Slug_Name',$page)->firstorFail();
        $pages = Page::all();
        return view('admin.pages.page',[
            'page' => $page,
        ],compact('pages'));
    }

My CostIncludeController:

    public function index($categories){
        $pages = Page::all();
        $packages = Package::where('slug',$categories)->first();
        return view('admin.pages.costinclude',[
            'packages' => $packages,
        ],compact('pages'));    
    }

My Route:

Auth::routes(['register' => false,'login' => false]);
Route::prefix('admin')->group(function() {
    Route::get('/')->name('login')->uses('Auth\LoginController@showLoginForm');
    Route::post('/')->name('login')->uses('Auth\LoginController@login');
    Route::get('/dashboard', 'AdminVisible\HomeController@index')->name('admin.dashboard');
    Route::prefix('pages')->group(function() {
        Route::get('/','AdminVisible\AdminPageController@pages')->name('pages');
        Route::prefix('{page}')->group(function() {
            Route::get('/','AdminVisible\AdminPageController@index')->name('page');
            Route::get('/banner', 'AdminVisible\BannerController@index');
            Route::get('/why-with-us', 'AdminVisible\WhyWithUsController@index');
            Route::get('/testimonials', 'AdminVisible\TestimonialsController@index');
            Route::get('/about', 'AdminVisible\AboutController@index');
            Route::get('/about-why-with-us', 'AdminVisible\AboutWhyWithUsController@index');
            Route::get('/general-information', 'AdminVisible\PackageController@index');
            Route::get('/package-program', 'AdminVisible\PackageController@index');
            Route::get('/cost-exclude', 'AdminVisible\PackageController@index');
            Route::prefix('cost-include')->group(function() {
                Route::get('/', 'AdminVisible\PackageController@index');
                Route::get('/{categories}', 'AdminVisible\CostIncludeController@index');
            });
        });
    }); 
});

My blade.php file:

@extends('layouts.app')
@section('style')
    <link href="{{ asset('css/Admin/sql-data-viewer.css') }}" rel="stylesheet">   
    <style></style>
@endsection
@section('content')
    <section class="data-viewer">
      <div class="d-flex justify-content-between">
        <h3>Select Package to change</h3>
        <a href="#"><button type="button" class="btn add-data text-white rounded-pill">Add &nbsp;<i class="fas fa-plus"></i></button></a>
      </div>
      <table>
          <thead>
              <tr class="data-head">  
                <td scope="col" style="width: 5%"><input type="checkbox"></td>
                <th scope="col" style="width: 8.7%">Id</th>
                <td scope="col">Includes</td> 
              </tr>
          </thead>
          <tbody>
            @foreach ($packages->costIncludes as $include)
              <tr class="data">
                <td scope="col" style="width: 6.5%"><input type="checkbox"></td>
                <th scope="col" style="width: 10%;"><a href="">{{$include->id}}</a></th>
                <td scope="col" class="text-justify" style="width:696px">{{Str::limit($include->Cost_Include,100)}}</td> 
              </tr>                                
                @endforeach
          </tbody>
      </table>

    </section>
@endsection

With {page} prefix:

enter image description here

Without {page} prefix:

enter image description here

With {page} prefix when i do dd(): enter image description here

Without {page} prefix when i do dd(): enter image description here

Nutan Panta
  • 59
  • 1
  • 16

2 Answers2

1

In your CostIncludeController@index, add the new variable. The router is expecting you to handle two variables.

public function index($page, $categories){
    $pages = Page::all();
    $packages = Package::where('slug',$categories)->first();
    return view('admin.pages.costinclude',[
        'packages' => $packages,
    ],compact('pages'));    
}

You can confirm the cause of the error by doing a dd($categories) inside your controller function in both cases.

N69S
  • 16,110
  • 3
  • 22
  • 36
  • i did even though the route is current it shows null which means i think page not found. but if i remove the page prefix from the route and do it it works. – Nutan Panta Aug 14 '20 at 11:26
0

It seems we need to pass $page parameter in the CostIncludesController. This same question is answered in this post:

I am having trouble with my route in laravel

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
Nutan Panta
  • 59
  • 1
  • 16
  • It looks to me like they did include the essential parts of the answer here and then linked for reference. This answer may be on the short side, but it looks complete to me. – Stephen Ostermiller Aug 14 '20 at 14:14