title: ErrorException Illegal offset type - Laravel
body: <p>have a problem, when I finish editing a product I must redirect to the previous view to continue loading products, but it gives me an error:  Illegal offset type - Laravel</p>
  <p>Function:</p>
  <pre><code> public function storeProduct(Request $request)
  {
      // $request-&gt;validate([
      //     'image' =&gt; 'mimes:jpeg,jpg,png,gif|max:10000',
      // ]);
      $subcategory = Subcategory::findOrFail($request-&gt;get('subcategory_id'));
      // dd($request-&gt;all());
      $fields = $request-&gt;except('_token', 'subcategory_id');
      // dd($fields);
      
          if ($request-&gt;file('image')) { 
              $image = $request-&gt;file('image');
              $fileName = $image-&gt;getClientOriginalName();
              $image-&gt;move(public_path('uploads/img/productos'), $fileName);
              $fields['image'] = &quot;uploads/img/productos/&quot; . $fileName;
          }
  
  
      
      $fields['visible'] = 1;
  
      $product = Product::firstOrCreate($fields);
      $subcategory-&gt;products()-&gt;attach($product);
  
      return redirect()-&gt;route('admin-products')-&gt;with($subcategory);
  }
  </code></pre>
  <p>error in line: **  return redirect()-&gt;route('admin-products')-&gt;with($subcategory);**</p>
  <p>Route:</p>
  <pre><code>Route::post('product/store', [
      'as' =&gt; 'admin-product-store',
      'uses' =&gt; 'AdminController@storeProduct'
  ]);
  
      Route::get('products/{id?}', [
      'as' =&gt; 'admin-products',
      'uses' =&gt; 'AdminController@products'
  ]);
  </code></pre>