title: Laravel Route Binding Model Undefined offset: 9
body: <p>I'm using laravel 5.2. I have a model called Book then try to move the route binding model from my controller to RouteServiceProvider.php</p>
  
  <p>here is my route binding model before i move it to the RouteServiceProvider.php</p>
  
  <pre><code>$book = Book::findOrFail($id);
  </code></pre>
  
  <p>after (in my RouteServiceProvider.php)</p>
  
  <pre><code>$router-&gt;model('book', 'App\Book');
  </code></pre>
  
  <p>It works prefectly before i move it to the RouteServiceProvider, but now it throw me an error eveytime i try to <strong>update</strong>, (create and store works fine).</p>
  
  <p>It failed to update the input to the database, but when i try to debug using <code>dd($this-&gt;method());</code> in the top of my rules on request, it say "PATCH" </p>
  
  <p>the error is <strong>Undefined offset: 9</strong> ...framework\src\Illuminate\Validation\Validator.php line 1461: <code>$extra[$segments[$i]] = $segments[$i + 1];</code></p>
  
  <p>I assume the error is from my update controller <code>return view('dashboards.book', compact('book'));</code> or mybe from the request conditional for the patch/update method</p>
  
  <p>Here is the complete code</p>
  
  <h3>Controller@update</h3>
  
  <pre><code>public function update(Book $book, BookRequest $request)
  {
      //$book = Book::findOrFail($id);  move to the RouteServiceProvider
  
      $input = $request-&gt;all();
  
      $book-&gt;update($request-&gt;all());
  
      //return view('dashboards.book');
      return view('dashboards.book', compact('book'));
  
  }
  </code></pre>
  
  <h3>BookRequest.php</h3>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Requests;
  
  use App\Http\Requests\Request;
  
  class BookRequest extends Request
  {
      /**
       * Determine if the user is authorized to make this request.
       *
       * @return bool
       */
      public function authorize()
      {
          return true;
      }
  
      /**
       * Get the validation rules that apply to the request.
       *
       * @return array
       */
      public function rules()
      {
  
          //$book = $this-&gt;route('book');
  
          //$this-&gt;route()-&gt;parameter('books');
  
          //dd($this-&gt;method());
  
  
  
          // Check Create or Update
          if ($this-&gt;method() == 'POST') {
              $label_rules = 'required|string|size:6|unique:books,label,';
              $isbn_rules = 'sometimes|string|size:10|unique:books,isbn,';
          }
  
          else {
              $label_rules = 'required|string|size:6|unique:books,label,' .$this-&gt;route()-&gt;parameter('book'); 
              $isbn_rules = 'sometimes|string|size:10|unique:books,isbn,' .$this-&gt;route()-&gt;parameter('book');
          }
  
  
  
  
          return [
              'judul'             =&gt; 'required|string|max:100',
              'label'             =&gt; $label_rules,
              'isbn'              =&gt; $isbn_rules,
              'tanggal_terbit'    =&gt; 'required|date',
              'status'            =&gt; 'required|in:tersedia,dipinjam,hilang,rusak',
              'id_penulis'        =&gt; 'required',
              'id_penerbit'       =&gt; 'required',
              'id_kategori'       =&gt; 'required',
          ];
  
  
      }
  }
  </code></pre>
  
  <h3>RouteServiceProvider.php</h3>
  
  <pre><code>&lt;?php
  
  namespace App\Providers;
  
  use Illuminate\Routing\Router;
  use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
  
  class RouteServiceProvider extends ServiceProvider
  {
      /**
       * This namespace is applied to the controller routes in your routes file.
       *
       * In addition, it is set as the URL generator's root namespace.
       *
       * @var string
       */
      protected $namespace = 'App\Http\Controllers';
  
      /**
       * Define your route model bindings, pattern filters, etc.
       *
       * @param  \Illuminate\Routing\Router  $router
       * @return void
       */
      public function boot(Router $router)
      {
          //
  
          parent::boot($router);
  
          // route model binding
          $router-&gt;model('book', 'App\Book');
      }
  
      /**
       * Define the routes for the application.
       *
       * @param  \Illuminate\Routing\Router  $router
       * @return void
       */
      public function map(Router $router)
      {
          $router-&gt;group(['namespace' =&gt; $this-&gt;namespace], function ($router) {
              require app_path('Http/routes.php');
          });
      }
  }
  </code></pre>
  
  <p>The Errors</p>
  
  <pre><code>in Validator.php line 1461
  at HandleExceptions-&gt;handleError('8', 'Undefined offset: 9', 'E:\YUDY\WEB PROJECT\CLIENTS\perpus lab\testroutemodelbinding\vendor\laravel\framework\src\Illuminate\Validation\Validator.php', '1461', array('segments' =&gt; array('label:"099187"', 'isbn:"9918892810"', 'tanggal_terbit:"2018-02-10"', 'status:"tersedia"', 'id_penerbit:1', 'id_kategori:1', 'id_penulis:1', 'created_at:"2018-01-02 00:01:26"', 'updated_at:"2018-01-02 00:01:26"}'), 'extra' =&gt; array('label:"099187"' =&gt; 'isbn:"9918892810"', 'tanggal_terbit:"2018-02-10"' =&gt; 'status:"tersedia"', 'id_penerbit:1' =&gt; 'id_kategori:1', 'id_penulis:1' =&gt; 'created_at:"2018-01-02 00:01:26"'), 'count' =&gt; '9', 'i' =&gt; '8')) in Validator.php line 1461
  at Validator-&gt;getExtraConditions(array('label:"099187"', 'isbn:"9918892810"', 'tanggal_terbit:"2018-02-10"', 'status:"tersedia"', 'id_penerbit:1', 'id_kategori:1', 'id_penulis:1', 'created_at:"2018-01-02 00:01:26"', 'updated_at:"2018-01-02 00:01:26"}')) in Validator.php line 1379
  at Validator-&gt;getUniqueExtra(array('books', 'label', '{"id":15', 'judul:"Fast And Furious"', 'label:"099187"', 'isbn:"9918892810"', 'tanggal_terbit:"2018-02-10"', 'status:"tersedia"', 'id_penerbit:1', 'id_kategori:1', 'id_penulis:1', 'created_at:"2018-01-02 00:01:26"', 'updated_at:"2018-01-02 00:01:26"}')) in Validator.php line 1338
  at Validator-&gt;validateUnique('label', '099187', array('books', 'label', '{"id":15', 'judul:"Fast And Furious"', 'label:"099187"', 'isbn:"9918892810"', 'tanggal_terbit:"2018-02-10"', 'status:"tersedia"', 'id_penerbit:1', 'id_kategori:1', 'id_penulis:1', 'created_at:"2018-01-02 00:01:26"', 'updated_at:"2018-01-02 00:01:26"}'), object(Validator)) in Validator.php line 485
  at Validator-&gt;validate('label', 'Unique') in Validator.php line 425
  at Validator-&gt;passes() in ValidatesWhenResolvedTrait.php line 24
  at FormRequest-&gt;validate() in FoundationServiceProvider.php line 41
  at FoundationServiceProvider-&gt;Illuminate\Foundation\Providers\{closure}(object(BookRequest), object(Application)) in Container.php line 1031
  at Container-&gt;fireCallbackArray(object(BookRequest), array(object(Closure))) in Container.php line 994
  at Container-&gt;fireResolvingCallbacks('App\Http\Requests\BookRequest', object(BookRequest)) in Container.php line 648
  at Container-&gt;make('App\Http\Requests\BookRequest', array()) in Application.php line 697
  at Application-&gt;make('App\Http\Requests\BookRequest') in RouteDependencyResolverTrait.php line 85
  at ControllerDispatcher-&gt;transformDependency(object(ReflectionParameter), array('book' =&gt; object(Book)), array('book' =&gt; object(Book))) in RouteDependencyResolverTrait.php line 58
  at ControllerDispatcher-&gt;resolveMethodDependencies(array('book' =&gt; object(Book)), object(ReflectionMethod)) in RouteDependencyResolverTrait.php line 41
  at ControllerDispatcher-&gt;resolveClassMethodDependencies(array('book' =&gt; object(Book)), object(DashboardController), 'update') in ControllerDispatcher.php line 143
  at ControllerDispatcher-&gt;call(object(DashboardController), object(Route), 'update') in ControllerDispatcher.php line 94
  at ControllerDispatcher-&gt;Illuminate\Routing\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
  at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
  at Pipeline-&gt;then(object(Closure)) in ControllerDispatcher.php line 96
  at ControllerDispatcher-&gt;callWithinStack(object(DashboardController), object(Route), object(Request), 'update') in ControllerDispatcher.php line 54
  at ControllerDispatcher-&gt;dispatch(object(Route), object(Request), 'App\Http\Controllers\DashboardController', 'update') in Route.php line 174
  at Route-&gt;runController(object(Request)) in Route.php line 140
  at Route-&gt;run(object(Request)) in Router.php line 724
  at Router-&gt;Illuminate\Routing\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
  at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 64
  at VerifyCsrfToken-&gt;handle(object(Request), object(Closure))
  at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
  at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
  at ShareErrorsFromSession-&gt;handle(object(Request), object(Closure))
  at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
  at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
  at StartSession-&gt;handle(object(Request), object(Closure))
  at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
  at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
  at AddQueuedCookiesToResponse-&gt;handle(object(Request), object(Closure))
  at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
  at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
  at EncryptCookies-&gt;handle(object(Request), object(Closure))
  at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
  at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
  at Pipeline-&gt;then(object(Closure)) in Router.php line 726
  at Router-&gt;runRouteWithinStack(object(Route), object(Request)) in Router.php line 699
  at Router-&gt;dispatchToRoute(object(Request)) in Router.php line 675
  at Router-&gt;dispatch(object(Request)) in Kernel.php line 246
  at Kernel-&gt;Illuminate\Foundation\Http\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
  at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
  at CheckForMaintenanceMode-&gt;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-&gt;Illuminate\Pipeline\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
  at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
  at Pipeline-&gt;then(object(Closure)) in Kernel.php line 132
  at Kernel-&gt;sendRequestThroughRouter(object(Request)) in Kernel.php line 99
  at Kernel-&gt;handle(object(Request)) in index.php line 53
  at require_once('E:\YUDY\WEB PROJECT\CLIENTS\perpus lab\testroutemodelbinding\public\index.php') in server.php line 21
  </code></pre>
  
  <p>Any suggestion for the error?</p>