app/Http/Controllers/TinTucController.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)
    {
        $tintuc= tinTuc::findOrFail($id);
        $imageName = ($request->hinhanh)?$request->hinhanh->getClientOriginalName():false;
        if($imageName){
            $tintuc->hinhanh = $imageName;
            $request->validate([
                'hinhanh' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
            ]);
            $request->hinhanh->move(public_path('images'), $imageName);
        }
        $tintuc->tieude = $request->tieude;
        $tintuc->slug = $request->slug;
        $tintuc->noidung = $request->noidung;
        $tintuc->trangthai = ($request->trangthai='on')?true:false;
        $tintuc->tacgia = $request->tacgia;
        $tintuc->save();
        return back()
            ->with('success','Sửa thành công')
            ->with('image',($imageName)?$imageName:'Không có thay đổi hình ảnh');
    }
public function update ( Request $ request , $ id ) { $ tintuc = tinTuc :: findOrFail ( $ id ) ; $ imageName = ( $ request -> hinhanh ) ? $ request -> hinhanh -> getClientOriginalName ( ) : false ; if ( $ imageName ) { $ tintuc -> hinhanh = $ imageName ; $ request -> validate ( [ 'hinhanh' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048' , ] ) ; $ request -> hinhanh -> move ( public_path ( 'images' ) , $ imageName ) ; } $ tintuc -> tieude = $ request -> tieude ; $ tintuc -> slug = $ request -> slug ; $ tintuc -> noidung = $ request -> noidung ; $ tintuc -> trangthai = ( $ request -> trangthai = 'on' ) ? true : false ; $ tintuc -> tacgia = $ request -> tacgia ; $ tintuc -> save ( ) ; return back ( ) -> with ( 'success' , 'Sửa thành công') -> with ( 'image' , ( $ imageName ) ? $ imageName : 'Không có thay đổi hình ảnh'); }
Update the specified resource in storage.
Update the specified resource in storage .
// //