app/Http/Controllers/ReportController.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)
    {
        $update_validator = $this->validator($request->all());
        if ($update_validator->fails()) {
            $this->throwValidationException(
                $request, $update_validator
                );
        } else {
            $user                   = \Auth::user();
            $report                 = Report::find($id);
            $report->description    = $request->input('description');
            $report->belongs_to     = $request->input('client');
            $file = NULL;
            if(Input::file('upload') != NULL){
                $report->name       = $request->input('name');
                $upload             = Input::file('upload');
                $filename           = str_replace(' ', '_', $report->name) .'.' . $upload->getClientOriginalExtension();
                $save_path          = '/users/id/' . $report->owner->id . '/uploads/reports/';
                unlink(storage_path().$save_path.$report->name . '.' . $report->extension);
                $upload->move(storage_path().$save_path, $filename);
                $file = '/files/users/' . $report->owner->id . '/reports/' . $filename;
                $report->storage    = $file;
                $report->extension  = $upload->getClientOriginalExtension();
            } else {
                if ($report->name != $request->input('name')) {
                    $save_path          = '\users\id\\' . $report->owner->id . '\uploads\reports\\';
                    rename(
                        storage_path(). $save_path. str_replace(' ', '_', $report->name) . '.' . $report->extension,
                        storage_path(). $save_path. str_replace(' ', '_', $request->input('name')) . '.' . $report->extension
                    );
                    $report->name       = $request->input('name');
                    $filename           = str_replace(' ', '_', $report->name) .'.' . $report->extension;
                    $file               = '/files/users/' . $report->owner->id . '/reports/' . $filename;
                    $report->storage    = $file;
                }
            }
            $report->save();
            return redirect('report')->with('status', 'Reporte modificado éxitosamente!');
        }
    }
public function update ( Request $ request , $ id ) { $ update_validator = $ this -> validator ( $ request -> all ( ) ) ; if ( $ update_validator -> fails ( ) ) { $ this -> throwValidationException ( $ request , $ update_validator ) ; } else { $ user = \ Auth :: user ( ) ; $ report = Report :: find ( $ id ) ; $ report -> description = $ request -> input ( 'description' ) ; $ report -> belongs_to = $ request -> input ( 'client' ) ; $ file = NULL ; if ( Input :: file ( 'upload' ) != NULL ) { $ report -> name = $ request -> input ( 'name' ) ; $ upload = Input :: file ( 'upload' ) ; $ filename = str_replace ( ' ' , '_' , $ report -> name ) . '.' . $ upload -> getClientOriginalExtension ( ) ; $ save_path = '/users/id/' . $ report -> owner -> id . '/uploads/reports/' ; unlink ( storage_path ( ) . $ save_path . $ report -> name . '.' . $ report -> extension ) ; $ upload -> move ( storage_path ( ) . $ save_path , $ filename ) ; $ file = '/files/users/' . $ report -> owner -> id . '/reports/' . $ filename ; $ report -> storage = $ file ; $ report -> extension = $ upload -> getClientOriginalExtension ( ) ; } else { if ( $ report -> name != $ request -> input ( 'name' ) ) { $ save_path = '\users\id\\' . $ report -> owner -> id . '\uploads\reports\\' ; rename ( storage_path ( ) . $ save_path . str_replace ( ' ' , '_' , $ report -> name ) . '.' . $ report -> extension , storage_path ( ) . $ save_path . str_replace ( ' ' , '_' , $ request -> input ( 'name' ) ) . '.' . $ report -> extension ) ; $ report -> name = $ request -> input ( 'name' ) ; $ filename = str_replace ( ' ' , '_' , $ report -> name ) . '.' . $ report -> extension ; $ file = '/files/users/' . $ report -> owner -> id . '/reports/' . $ filename ; $ report -> storage = $ file ; } } $ report -> save ( ) ; return redirect ( 'report' ) -> with ( 'status' , 'Reporte modificado éxitosamente!') ; } }
Update the specified resource in storage.
Update the specified resource in storage .
// $report->uploaded_by    = $user->id; // CHECK FOR REPORT FILE UPLOAD // MAKE USER FOLDER AND UPDATE PERMISSIONS // File::makeDirectory(storage_path(). $save_path, $mode = 0755, true, true); // SAVE FILE TO SERVER // Storage::put($save_path.$filename, $upload); // $upload->move(base_path().'/public/reports'.$save_path, $filename); // SAVE ROUTED PATH TO IMAGE TO DATABASE // $report->storage    = $file;