app/Http/Controllers/Backend/ProductController.php
/**
     * Update the specified resource in storage.
     *
     * @param \Illuminate\Http\Request $request
     * @param int $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
    {
        $validated = $request->validate([
            'name' => 'required|string',
            'price' => 'required',
            'insurance' => 'required',
            'deposit' => 'required',
            'km' => 'required',
            'additional' => 'required',
            'engine' => 'required',
            'seat' => 'required',
            'capacity' => 'required',
            'range' => 'required',
            'gear' => 'required',
            'consumption' => 'required',
            'brand_id' => 'required',
            'district_id' => 'required',
            'category_id' => 'required',
            'city_id' => 'required'
        ]);
        $product = Product::find($id);
        $product->name = $request->name;
        $get_image = $request->file('image');
        if ($request ->image != null){
            $image = base64_encode(file_get_contents($_FILES['image']['tmp_name']));
            $options = array('http' =>array(
                'method' => "POST",
                'header' => "Authorization: Bearer 3597bf9393d8155003c84329d6205961426482fc\n".
                    "Content-Type: application/x-www-form-urlencoded",
                'content' => $image
            ));
            $context = stream_context_create($options);
            $imgurURL = "https://api.imgur.com/3/image";
            $response = file_get_contents($imgurURL, false, $context);
            $response = json_decode($response);
            $msg = $response->data->link;
            $product -> image = $msg;
        }
        $product->price = $request->price;
        $product->insurrance = $request->insurance;
        $product->deposit = $request->deposit;
        $product->km = $request->km;
        $product->additional = $request->additional;
        $product->engine = $request->engine;
        $product->seat = $request->seat;
        $product->capacity = $request->capacity;
        $product->range = $request->range;
        $product->gear = $request->gear;
        $product->status = 'ready';
        $product->consumption = $request->consumption;
        $product->district_id = $request->district_id;
        $product->brand_id = $request->brand_id;
        $product->category_id = $request->category_id;
        $product->city_id = $request->city_id;
        $product->update();
        $request->session()->flash('success', 'Cập nhật phương tiện thành công!');
        return redirect()->route('product.index');
    }
public function update ( Request $ request , $ id ) { $ validated = $ request -> validate ( [ 'name' => 'required|string' , 'price' => 'required' , 'insurance' => 'required' , 'deposit' => 'required' , 'km' => 'required' , 'additional' => 'required' , 'engine' => 'required' , 'seat' => 'required' , 'capacity' => 'required' , 'range' => 'required' , 'gear' => 'required' , 'consumption' => 'required' , 'brand_id' => 'required' , 'district_id' => 'required' , 'category_id' => 'required' , 'city_id' => 'required' ] ) ; $ product = Product :: find ( $ id ) ; $ product -> name = $ request -> name ; $ get_image = $ request -> file ( 'image' ) ; if ( $ request -> image != null ) { $ image = base64_encode ( file_get_contents ( $ _FILES [ 'image' ] [ 'tmp_name' ] ) ) ; $ options = array ( 'http' => array ( 'method' => " POST " , 'header' => " Authorization: Bearer 3597bf9393d8155003c84329d6205961426482fc \n " . " Content-Type: application/x-www-form-urlencoded " , 'content' => $ image ) ) ; $ context = stream_context_create ( $ options ) ; $ imgurURL = " https://api.imgur.com/3/image " ; $ response = file_get_contents ( $ imgurURL , false , $ context ) ; $ response = json_decode ( $ response ) ; $ msg = $ response -> data -> link ; $ product -> image = $ msg ; } $ product -> price = $ request -> price ; $ product -> insurrance = $ request -> insurance ; $ product -> deposit = $ request -> deposit ; $ product -> km = $ request -> km ; $ product -> additional = $ request -> additional ; $ product -> engine = $ request -> engine ; $ product -> seat = $ request -> seat ; $ product -> capacity = $ request -> capacity ; $ product -> range = $ request -> range ; $ product -> gear = $ request -> gear ; $ product -> status = 'ready' ; $ product -> consumption = $ request -> consumption ; $ product -> district_id = $ request -> district_id ; $ product -> brand_id = $ request -> brand_id ; $ product -> category_id = $ request -> category_id ; $ product -> city_id = $ request -> city_id ; $ product -> update ( ) ; $ request -> session ( ) -> flash ( 'success' , 'Cập nhật phương tiện thành công!'); return redirect ( ) -> route ( 'product.index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .