samedi 1 août 2020

how to update two tables with db: transaction laravel

in my code controller

    public function update(Request $request,$id) {
    $data = $request->all();
    $validator = Validator::make($data, [
        'title'                  => 'required',
        'order_'  => 'required',
        'active'               => 'required',
        'url'               => 'required',
        'category'           => 'required'
    ]);
    $errors=$validator->errors();
    if ($validator->fails()) {
        return Redirect::to('admin/video/video/'.$id.'/edit')
            ->withErrors($errors)
            ->withInput();
    }
    $data['lokit_category_id'] = $data['category'];
    unset($data['category']);
    DB::beginTransaction();
    try {
        if($request->hasFile('cover_img')) {
            $uniquename='cvr_'.md5($id);
            $filename=$uniquename.'.'.$request->file('cover_img')->getClientOriginalExtension();
            $path=public_path('storage/media');
            $request->cover_img->move($path, $filename);
            $data['cover_img']=$filename;
            
            $this->_resizeimg($path,$filename,$uniquename);  
        }
        $isi = Video::find($id);
        if($isi->url != $data['url']) {
            $name = str_replace("_", '',$data['url']);
            $manager = new MediaManager('/uploads');
            $manager->newFolder($name);
            $data['duration'] = $this->getDuration($data['url']);
        }
        
        $isi->update($data);
        if (isset($request->series) && $request->series) {
            $video_series = new VideoSeries();
            $video_series->lokit_video_id =$id;
            $video_series->lokit_series_id = (int)$request->series;
            $video_series->series = (int)$request->episode;
            $isi->video_series()->update($video_series);
        }
        DB::commit();
        return Redirect::to('admin/video/video');
    } catch (\Exception $ex) {
        DB::rollback();
        throw $ex;
    }
}

When I tried the code above I even experienced an error like this Argument 1 passed to Illuminate \ Database \ Eloquent \ Builder :: update () must be of the type array, object given, how to fix the error



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/311VO8w
via IFTTT

Aucun commentaire:

Enregistrer un commentaire