zunkt
1 month ago
154
2
Laravel

Database Update Not Update. it reappeared

Posted 1 month ago by zunkt

Hi! I want to update my product database. But somehow when i click submit. The database not update. They reappeared again. Here my code:

Edit View:

<form method="POST" action="{{ route('products.update', $product->id) }}">
	 @csrf
         @method('PUT')
                <select id="brand_id" name="brand_id">
                    @foreach($brands as $brand)
                        <option value="{{ $brand->id }}">{{ $brand->name }}</option>
                    @endforeach
                </select>
                <label class="label" for="sku">sku</label>
                <textarea name="sku" id="sku">{{ $product->sku }}</textarea>
                <label class="label" for="name">name</label>
                <input class="input" type="text" name="name" id="name" value="{{ $product->name }}">
                <label class="label" for="description">description</label>
                <textarea class="textarea" name="description" id="description">{{ $product->description }}</textarea>
                <label class="label" for="description">quantity</label>
                <input type="number" name="quantity" id="quantity" value="{{ $product->quantity }}">
                <label class="label" for="description">weight</label>
                <input type="number" name="weight" id="weight" value="{{ $product->weight }}">
                <label class="label" for="description">price</label>
                <input type="number" name="price" id="price" value="{{ $product->price }}">
                <label class="label" for="description">sale_price</label>
                <input type="number" name="sale_price" id="sale_price" value="{{ $product->sale_price }}">
                <label class="lable" for="status">Choose a status Value:</label>

Here my Update Controller:

 public function edit(Product $product)
    {
        $brands = Brand::all();
        return view('products.edit', ['product' => $product], ['brands' => $brands]);
    }

    public function update(Product $product, ProductRequest $request)
    {
        $product->update($request->all());
        return 'update Susscess';
    }

Here My Product Request:

 public function rules()
    {
        return [
            'brand_id' => ['required', 'int', 'nullable'],
            'sku' => ['required', 'string', 'max:50'],
            'name' => ['required', 'string', 'max:100'],
            'description' => ['required', 'string', 'nullable'],
            'weight' => ['required', 'int', 'nullable'],
            'price' => ['required', 'int', 'nullable'],
            'sale_price' => ['required', 'int', 'nullable'],
            'status' => ['required', 'boolean'],
            'featured' => ['required', 'boolean'],
        ];
    }

Thanks

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