All individual subscriptions are 50% off this week only!

kgp43
1 year ago

How to just update one "cell" in my table without getting fields_required?

Posted 1 year ago by kgp43

Hi,

I hope one of you might be able to help me with a problem. How can I update just one "cell" in my database-table?

I have tried to use the update method in my controller, but getting fields_required errors for the other ... stuff - the values I don't wanna update.

I try to update the "salesprice" in my ProductController:

public function update(UpdateProduct $request, $id)
    {

        $product = Product::findOrFail($id);
        
        $product->category              = $request->input('category');
        $product->part_number           = $request->input('part_number');
        $product->productname           = $request->input('productname');
        $product->internal_notes        = $request->input('internal_notes');
        $product->description           = $request->input('description');
        $product->salesprice            = $request->input('salesprice');
        
        $product->save();
        
        Toastr::success('Ændringer gemt', 'Handling udført');

        return redirect()->route('product.show', $id);
    }

My UpdateProduct request:

public function rules()
    {
        
        return [
            'category'               => 'required|max:255',
            'part_number'            => 'required|max:20|unique:products',
            'productname'            => 'required|max:255',
            'description'            => '',
            'internal_notes'         => '',
            'salesprice'             => '',
        ];
        
    }

I get what is happening, or so I think: My submit form only include one input, the "salesprice", that leave the rest (category, part_number and productname) empty, and thats why I receive the error.

I'm not sure how to get around it though.

Hope so get some nice input from you smart people :)

Please sign in or create an account to participate in this conversation.