app/Http/Controllers/ArtistController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\NgheNhan  $ngheNhan
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
    {
        $data = NgheNhan::find($id);
        $data->tenNgheNhan = $request->input('tenNgheNhan');
        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->moTa = $request->input('moTa');
        $trangThai=0;
        $data->slug = Str::slug($request->input('tenNgheNhan'));
        if($request->has('trangThai')) 
        {
            $trangThai = $request->input('trangThai');
        }
        $data->trangThai = $trangThai;
        $data->save();
        return redirect('admin/artist');
    }
public function update ( Request $ request , $ id ) { $ data = NgheNhan :: find ( $ id ) ; $ data -> tenNgheNhan = $ request -> input ( 'tenNgheNhan' ) ; 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 -> moTa = $ request -> input ( 'moTa' ) ; $ trangThai = 0 ; $ data -> slug = Str :: slug ( $ request -> input ( 'tenNgheNhan' ) ) ; if ( $ request -> has ( 'trangThai' ) ) { $ trangThai = $ request -> input ( 'trangThai' ) ; } $ data -> trangThai = $ trangThai ; $ data -> save ( ) ; return redirect ( 'admin/artist' ) ; }
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