app/Http/Controllers/ReportController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $create_new_validator = $this->create_validator($request->all());
        if ($create_new_validator->fails()) {
            $this->throwValidationException(
                $request, $create_new_validator
                );
        } else {
            $user                   = \Auth::user();
            $report                 = new Report;
            $report->name           = $request->input('name');
            $report->description    = $request->input('description');
            $report->belongs_to     = $request->input('client');
            $report->uploaded_by    = $user->id;
            $file = NULL;
            if(Input::file('upload') != NULL){
                $upload             = Input::file('upload');
                $filename           = str_replace(' ', '_', $report->name) .'.' . $upload->getClientOriginalExtension();
                $save_path          = '/users/id/' . $user->id . '/uploads/reports/';
                $upload->move(storage_path().$save_path, $filename);
                $file = '/files/users/' . $user->id . '/reports/' . $filename;
                $report->extension  = $upload->getClientOriginalExtension();
            }
            $report->storage = $file;
            $report->save();
            return redirect('report')->with('status', 'Reporte subido éxitosamente!');
        }
    }
public function store ( Request $ request ) { $ create_new_validator = $ this -> create_validator ( $ request -> all ( ) ) ; if ( $ create_new_validator -> fails ( ) ) { $ this -> throwValidationException ( $ request , $ create_new_validator ) ; } else { $ user = \ Auth :: user ( ) ; $ report = new Report ; $ report -> name = $ request -> input ( 'name' ) ; $ report -> description = $ request -> input ( 'description' ) ; $ report -> belongs_to = $ request -> input ( 'client' ) ; $ report -> uploaded_by = $ user -> id ; $ file = NULL ; if ( Input :: file ( 'upload' ) != NULL ) { $ upload = Input :: file ( 'upload' ) ; $ filename = str_replace ( ' ' , '_' , $ report -> name ) . '.' . $ upload -> getClientOriginalExtension ( ) ; $ save_path = '/users/id/' . $ user -> id . '/uploads/reports/' ; $ upload -> move ( storage_path ( ) . $ save_path , $ filename ) ; $ file = '/files/users/' . $ user -> id . '/reports/' . $ filename ; $ report -> extension = $ upload -> getClientOriginalExtension ( ) ; } $ report -> storage = $ file ; $ report -> save ( ) ; return redirect ( 'report' ) -> with ( 'status' , 'Reporte subido éxitosamente!') ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .
// 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