اذهب إلى المحتوى
  • 0

طريقة put لا تعمل في Laravel

محمد لارافيل

السؤال

أنا أستخدم طريقة PUT في أحد المسارات ولكن يظهر لي انه غير مسموح به
Controller

public function edit(Product $product)
{
return view('products_update', compact('product'));
}

    public function edit(Product $product) { return view('products_update', compact('product')); }
    
    public function update(Request $request, $id)
    {
        $validatedData = $request->validate([
            'name' => 'required',
            'desc' => 'required',
            'price' => 'required|numeric',
            'qty' => 'required',
            // Add more validation rules for other fields if needed
        ]);
    
        // Update the product
        $newTitle = $request->input('product_title');
        $newDesc= $request->input('product_desc');
        $newPrice= $request->input('product_price');
        $newQty= $request->input('product_qty');
    
        // Update other fields if needed
        //$product->save();
    
        DB::update('update products set title = ?, desc = ?, price = ?, qty = ? where id = ?', 
        [$newTitle, $newDesc, $newPrice, $newQty]);
    
        // Redirect to the index page or show a success message
        return redirect()->route('products.index')->with('success', 'Product updated successfully.');
    }

blade

<form action="{{ route('products.edit', $product->id) }}" method="post">
    @method('PUT')
    <!-- <input type="hidden" id="_token" value="{{ csrf_token() }}"> -->
    @csrf

route

Route::get('/products/{product}/edit', \[ProductController::class,'edit'\])-\>name('products.edit');
Route::put('/products/{id}', \[ProductController::class, 'update'\])-\>name('products.update');

أرجو منكم المساعدة
شكرا لكم

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

لا توجد أي إجابات على هذا السؤال بعد

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...