samedi 25 août 2018

Missing required parameters for [Route: products.update] [URI: {store}/products/{products}/edit]

When I try to view my edit page, this error comes up and my update route seems to be the problem.

What I want to happen is that, there is a store, and in that store, there are products. and I should be able to edit those products.

Here is my Routes for both Get and Post request

    Route::get('{store}/products/{products}/edit', [
    'as'    => 'products.edit',
    'uses'  => 'ProductsController@edit'
]);

Route::post('{store}/products/{products}/edit', [
    'as'    => 'products.update',
    'uses'  => 'ProductsController@update'
]);

and here is my controller:

    public function edit($store, $id)
{
    $store = Store::where('slug', $store)->firstOrFail();
    $product = $store->products()->findOrFail($id);
    return view('products.edit', compact('product'));
}

    public function update(Request $request, $store, $id)
{
    $store = Store::where('slug', $store)->firstOrFail();
    $product = $store->products()->findOrFail($id);

    $this->validate($request, [
        'name'          => 'required',
        'upload_media'  => 'sometimes|required|file|image'
    ]);

    DB::transaction(function () use ($request, &$product) {

        $product->name = $request->input('name');
        $product->save();

        if ($request->hasFile('upload_media') &&
            $request->file('upload_media')->isValid()) {
            // Upload a new file to the product's media
            $product->addMediaFromRequest('upload_media')
                  ->usingFileName($request->file('upload_media')->hashName())
                  ->toMediaCollection('images', 's3-public-uploads');
        }

        foreach ($request->input('delete_media', []) as $for_deletion) {
            $media_for_deletion = $product->media()->find($for_deletion);

            if ($media_for_deletion) {
                $media_for_deletion->delete();
            }
        }

    });

    return redirect()->route('products.edit', $product->uuid);
}

and lastly, my edit.blade.php

//some html here
            {!! Form::open([ 'route'    => [ 'products.update', $product->uuid ],
                             'files'    => true,
                             'method'   => 'PUT' ]) !!}

//some more html for form here
                    <button class="btn btn-default" type="submit">Update Store</button>
                </div>
            </div>
            {!! Form::close() !!}
        </div>
    </div>
</div>
@endsection

I have also tried to change 'post' to 'put' but I still get the same error.

errors are:

Missing required parameters for [Route: developer.products.update] [URI: {store}/products/{products}/edit]. (View: /Users/user/sample/resources/views/products/edit.blade.php)

and

Missing required parameters for [Route: products.update] [URI: {store}/products/{products}/edit].



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2PGbLef
via IFTTT

Aucun commentaire:

Enregistrer un commentaire