app/Http/Controllers/ProductController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\SanPham  $sanPham
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
    {
        $data = SanPham::find($id);
        $data->ten = $request->input('ten');
        $data->idHang = $request->input('idHang');
        $idKhoiLuong=0;
        foreach ($request->input('idKhoiLuong')as$rq){
            $idKhoiLuong=$idKhoiLuong.",".$rq;
        }
        $data->idKhoiLuong = substr($idKhoiLuong, 2);
        $data->gia = $request->input('gia');
        if($request->hasFile('image_new')){
            @unlink(public_path($data->image));
            $file = $request->file('image_new');
            $ten_image = time() . '_' . $file->getClientOriginalName();
            $path_upload = 'upload/news/';
            $request->file('image_new')->move($path_upload, $ten_image);
            $data->image = $path_upload . $ten_image;
        }
        $data->cachDung = $request->input('cachDung1')."@".$request->input('cachDung2')."@".$request->input('cachDung3');
        $data->slug = Str::slug($request->input('tenTinTuc'));
        $trangThai=0;
        $hot=0;
        if($request->has('hot')) 
        {
            $hot = $request->input('hot');
        }
        $data->hot = $hot;
        $data->moTaChiTiet = $request->input('moTaChiTiet');
        if($request->has('trangThai')) 
        {
            $trangThai = $request->input('trangThai');
        }
        $data->trangThai = $trangThai;
        $data->save();
        return redirect('admin/product');
    }
public function update ( Request $ request , $ id ) { $ data = SanPham :: find ( $ id ) ; $ data -> ten = $ request -> input ( 'ten' ) ; $ data -> idHang = $ request -> input ( 'idHang' ) ; $ idKhoiLuong = 0 ; foreach ( $ request -> input ( 'idKhoiLuong' ) as $ rq ) { $ idKhoiLuong = $ idKhoiLuong . " , " . $ rq ; } $ data -> idKhoiLuong = substr ( $ idKhoiLuong , 2 ) ; $ data -> gia = $ request -> input ( 'gia' ) ; if ( $ request -> hasFile ( 'image_new' ) ) { @ unlink ( public_path ( $ data -> image ) ) ; $ file = $ request -> file ( 'image_new' ) ; $ ten_image = time ( ) . '_' . $ file -> getClientOriginalName ( ) ; $ path_upload = 'upload/news/' ; $ request -> file ( 'image_new' ) -> move ( $ path_upload , $ ten_image ) ; $ data -> image = $ path_upload . $ ten_image ; } $ data -> cachDung = $ request -> input ( 'cachDung1' ) . " @ " . $ request -> input ( 'cachDung2' ) . " @ " . $ request -> input ( 'cachDung3' ) ; $ data -> slug = Str :: slug ( $ request -> input ( 'tenTinTuc' ) ) ; $ trangThai = 0 ; $ hot = 0 ; if ( $ request -> has ( 'hot' ) ) { $ hot = $ request -> input ( 'hot' ) ; } $ data -> hot = $ hot ; $ data -> moTaChiTiet = $ request -> input ( 'moTaChiTiet' ) ; if ( $ request -> has ( 'trangThai' ) ) { $ trangThai = $ request -> input ( 'trangThai' ) ; } $ data -> trangThai = $ trangThai ; $ data -> save ( ) ; return redirect ( 'admin/product' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
//has(name-input) //has-kiểm tra tồn tại hay ko //has(name-input) //has-kiểm tra tồn tại hay ko