title: I am getting 500 Internal Error when trying to pass named route with two parameter in my controller
body: <p>So when I put a route name with a single parameter it works flawlessly but when I pass named route with two parameters I get a 500 error in my console which looks like this:<code>GET http://127.0.0.1:8000/admin/packages/package-programs/kathmandu/action?query= 500 (Internal Server Error)</code>.</p>
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers\AdminVisible;
  
  use Illuminate\Http\Request;
  use Illuminate\Support\Str;
  use App\Program;
  use App\Package;
  use DB;
  
  class PackageProgramController extends Controller
  {
      public function __construct()
      {
          $this-&gt;middleware('auth');
      }
  
      public function index($packageSlug)
      {
          $showCounts = Program::count();
          $packages = Package::firstOrFail();
          return view('admin.pages.packageprogram',compact('showCounts','packageSlug','packages'));      
      }
  
      function action($packageSlug,Request $request)
      {
          if($request-&gt;ajax())
          {
           $output = '';
           $query = $request-&gt;get('query');
           if($query != '')
           {
            $data = DB::table('programs')
              -&gt;where('id', 'like', '%'.$query.'%')
              -&gt;orWhere('day', 'like', '%'.$query.'%')
              -&gt;orWhere('Package_Type', 'like', '%'.$query.'%')
              -&gt;orWhere('title', 'like', '%'.$query.'%')
              -&gt;orderBy('id', 'desc')
              -&gt;get();
              
           }
           else
           {
            $data = DB::table('programs')
              -&gt;orderBy('id', 'desc')
              -&gt;get();
           }
           $total_row = $data-&gt;count();
  
           if($total_row &gt; 0)
           {
            foreach($data as $row)
            {
              $packageProgram = ['packageProgram' =&gt; $row-&gt;id];
              $route = route('PackageProgram.edit',['packageSlug' =&gt; $packageSlug, 'packageProgram' =&gt; $packageProgram]);
             $output .= '
              
             &lt;tr&gt;
             &lt;th scope=&quot;row&quot;&gt;&lt;input type=&quot;checkbox&quot; name=&quot;ids[]&quot; class=&quot;selectbox&quot; value=&quot;'.$row-&gt;id.'&quot; onchange=&quot;change()&quot;&gt;&lt;/th&gt;
              &lt;td onClick=&quot;location.href=\''.$route.'\' &quot; style=&quot;cursor: pointer&quot;&gt;'.$row-&gt;id.'&lt;/td&gt;
              &lt;td onClick=&quot;location.href=\''.$route.'\' &quot; style=&quot;cursor: pointer&quot;&gt;'.$row-&gt;day.'&lt;/td&gt;
              &lt;td onClick=&quot;location.href=\''.$route.'\' &quot; style=&quot;cursor: pointer&quot;&gt;'.$row-&gt;title.'&lt;/td&gt;
              &lt;td onClick=&quot;location.href=\''.$route.'\' &quot; style=&quot;cursor: pointer&quot;&gt;'.$row-&gt;description.'&lt;/td&gt;
  
             &lt;/tr&gt;
             ';
            }
           }
           else
           {
            $output = '
            &lt;tr&gt;
             &lt;td align=&quot;center&quot; colspan=&quot;12&quot;&gt;No Data Found&lt;/td&gt;
            &lt;/tr&gt;
            ';
           }
           $data = array(
            'table_data'  =&gt; $output,
            'total_data'  =&gt; $total_row
           );
     
           echo json_encode($data);
          }
      }
  
      public function create($packageSlug, Package $package) 
      {
          return view('admin.create.createPackageProgram',compact('packageSlug','package'));
      }
  
      public function store($packageSlug,Request $request) 
      {
          $packages = Package::where('slug', $packageSlug)-&gt;firstOrFail();
          $data = request()-&gt;validate([
              'day' =&gt; 'required',             
              'title' =&gt; 'required',
              'description' =&gt; 'required', 
          ]);
          $packages-&gt;program()-&gt;create($data);
          switch ($request-&gt;input('action')) {
          case 'preview':
              return redirect()-&gt;intended(route('PackageProgram',$packageSlug))-&gt;with('message', 'Package Program has been added.');
              break;
          
          default:
              return redirect()-&gt;back()-&gt;with('message', 'Package Program has been added.');
              break;
          }
      }
  
      public function edit($packageSlug,Program $packageProgram,Package $package)  
      {
          return view('admin.edit.editPackageProgram',compact('packageSlug','packageProgram','package'));
      }
  
      public function update($packageSlug, Program $packageProgram)
      {
          $data = request()-&gt;validate([
              'day' =&gt; 'required',
              'title' =&gt; 'required',
              'description' =&gt; 'required',
          ]);
          $packageProgram-&gt;update($data);
          return redirect()-&gt;intended(route('PackageProgram',$packageSlug))-&gt;with('message', 'Package Program has been updated.');
      }
  
      public function delete(Request $request) {
          $data = request()-&gt;validate([
              'deleteSelected' =&gt; 'required',
          ]);
          $id = $request-&gt;get('ids');
          $data = DB::delete('delete from programs where id in ('.implode(&quot;,&quot;,$id).')');
          return redirect()-&gt;back()-&gt;with('message', 'Testimony has been deleted.');
      }
  }
      
  </code></pre>
  <p>My blade file looks something like this:</p>
  <pre><code>@extends('layouts.app')
  @section('style')
      &lt;link href=&quot;{{ asset('css/Admin/sql-data-viewer.css') }}&quot; rel=&quot;stylesheet&quot;&gt;   
      &lt;style&gt;&lt;/style&gt;
  @endsection
  @section('content')
  &lt;section class=&quot;data-viewer&quot;&gt;
    &lt;div class=&quot;d-flex justify-content-between px-3&quot;&gt;
      &lt;h3 class=&quot;text-white&quot;&gt;Select {{$package-&gt;Package_Name}} {{$package-&gt;Package_Type}} Days to change&lt;/h3&gt;
    &lt;a href=&quot;{{ route('PackageProgram.create',$packageSlug) }}&quot;&gt;&lt;button type=&quot;button&quot; class=&quot;btn add-data text-white rounded-pill&quot;&gt;Add Day &amp;nbsp;&lt;i class=&quot;fas fa-plus&quot;&gt;&lt;/i&gt;&lt;/button&gt;&lt;/a&gt;
    &lt;/div&gt;
    &lt;form&gt;
      @csrf
      @method('DELETE')
      @if(session()-&gt;has('message'))
      &lt;div class=&quot;alert alert-success&quot;&gt;
          {{ session()-&gt;get('message') }}
      &lt;/div&gt;
      @endif 
      &lt;div class=&quot;d-flex justify-content-between selectDelete&quot;&gt;
        &lt;div class=&quot;delete pl-3 mt-3 mb-3&quot;&gt;
          &lt;label for=&quot;deleteSelected&quot;&gt;Action:&lt;/label&gt;
          &lt;select name=&quot;deleteSelected&quot; id=&quot;deleteSelected&quot; class=&quot;@error('deleteSelected') is-invalid @enderror&quot; name=&quot;deleteSelected&quot; &gt;
            &lt;option disabled selected&gt;---------&lt;/option&gt;
            &lt;option&gt;Delete Selected Package Program&lt;/option&gt;
          &lt;/select&gt;
          &lt;button formaction=&quot;{{ route('PackageProgram.delete',$package) }}&quot; formmethod=&quot;POST&quot; type=&quot;submit&quot; class=&quot;go&quot; id=&quot;deleleGo&quot; onclick=&quot;deleteBtn()&quot;&gt;Go&lt;/button&gt; 
          &amp;nbsp;&amp;nbsp;&lt;span id=&quot;selected&quot;&gt;0&lt;/span&gt; of {{$showCounts}} selected
          @error('deleteSelected')
            &lt;span class=&quot;invalid-feedback&quot; role=&quot;alert&quot;&gt;
                &lt;strong&gt;{{ $message }}&lt;/strong&gt;
            &lt;/span&gt;
          @enderror
          &lt;strong id=&quot;selectError&quot;&gt;You must check at least one checkbox&lt;/strong&gt;             
        &lt;/div&gt;
        &lt;div class=&quot;search pr-3 mt-3 mb-3&quot;&gt;
          &lt;label for=&quot;search&quot;&gt;Search:&lt;/label&gt;
          &lt;input id=&quot;search&quot; type=&quot;text&quot; color=&quot;#000&quot; class=&quot;rounded @error('search') is-invalid @enderror&quot; name=&quot;search&quot; value=&quot;{{ old('search') }}&quot; autocomplete=&quot;search&quot; placeholder=&quot;Search&quot;&gt;
          @error('search')
            &lt;span class=&quot;invalid-feedback&quot; role=&quot;alert&quot;&gt;
                &lt;strong&gt;{{ $message }}&lt;/strong&gt;
            &lt;/span&gt;
          @enderror 
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;table class=&quot;table table-hover table-striped table-dark&quot;&gt;
        &lt;thead&gt;
          &lt;tr&gt;
            &lt;th scope=&quot;col&quot;&gt;&lt;input type=&quot;checkbox&quot; id=&quot;checkHead&quot; class=&quot;selectall&quot;&gt;&lt;/th&gt;
            &lt;th scope=&quot;col&quot;&gt;Id&lt;/th&gt;
            &lt;th scope=&quot;col&quot;&gt;Day&lt;/th&gt;
            &lt;th scope=&quot;col&quot;&gt;Title&lt;/th&gt;
            &lt;th scope=&quot;col&quot;&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tbody&gt;&lt;/tbody&gt;
      &lt;/table&gt;
    &lt;/form&gt;
  &lt;/section&gt;
  @endsection
  
  @section('script')
    &lt;script src=&quot;{{ asset('/js/sqlData.js') }}&quot;&gt;&lt;/script&gt;
    &lt;script&gt;
      $(document).ready(function(){
      
      fetch_data();
      
      function fetch_data(query = '')
      {
      $.ajax({
        url:&quot;{{ route('PackageProgram.action',$packageSlug) }}&quot;,
        method:'GET',
        data:{query:query},
        dataType:'json',
        success:function(data)
        {
        $('tbody').html(data.table_data);
        }
      })
      }
      
      $(document).on('keyup', '#search', function(){
      var query = $(this).val();
      fetch_data(query);
      });
      });
      function checkboxError(){
        var number = document.querySelectorAll('.selectbox:checked').length;
        if(number  == 0) {
          var a = document.getElementById(&quot;selectError&quot;).style.display = &quot;block&quot;;
          return false;
        }
      }
      window.addEventListener('DOMContentLoaded', (event) =&gt; {
        var deleteBtn = document.getElementById(&quot;deleleGo&quot;);
        deleteBtn.onclick = checkboxError;
      });
    &lt;/script&gt;
  @endsection
  </code></pre>
  <p>So my route file looks something like this:</p>
  <pre><code>        Route::prefix('package-programs')-&gt;group(function() {
              Route::get('/', 'AdminVisible\packagePackageProgramController@index')-&gt;name('PackagePrograms');
              Route::get('/action', 'AdminVisible\packagePackageProgramController@action')-&gt;name('PackagePrograms.action');
              Route::prefix('{packageSlug}')-&gt;group(function() {
                  Route::get('/', 'AdminVisible\PackageProgramController@index')-&gt;name('PackageProgram');
                  Route::get('/action', 'AdminVisible\PackageProgramController@action')-&gt;name('PackageProgram.action');
                  Route::get('/create', 'AdminVisible\PackageProgramController@create')-&gt;name('PackageProgram.create');
                  Route::post('/create', 'AdminVisible\PackageProgramController@store')-&gt;name('PackageProgram.store');
                  Route::delete('/delete','AdminVisible\PackageProgramController@delete')-&gt;name('PackageProgram.delete');
                  Route::get('/{packageProgram}/edit', 'AdminVisible\PackageProgramController@edit')-&gt;name('PackageProgram.edit');
                  Route::patch('/{packageProgram}', 'AdminVisible\PackageProgramController@update')-&gt;name('PackageProgram.update');
              });
          });
  </code></pre>
  <p>It might be I do not know how to pass named route with two parameters but in my blade file, I been doing it like this, and there it works. Is it something different that must be done in the controller.</p>