Hourlee
158
2
Laravel

Call to a member function getClientOriginalName() on null

Posted 10 months ago by Hourlee

Here's my controller

namespace App\Http\Controllers; use App\FileEntry; use App\Project as Project; use Illuminate\Http\Request; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Input; use Illuminate\Support\Facades\Storage;

class FileEntriesController extends Controller { public function index() { $files = FileEntry::all(); return view('files.index', compact('files')); } public function create() { return view('files.create'); } public function save($id, Request $request) { $this->validate($request, [ // 'file' => 'image|max:3000' ]);

    $file = Input::file('file');

    $filename = $file->getClientOriginalName();

    $path = hash( 'sha256', time());
    if(Storage::disk('uploads')->put($path.'/'.$filename,  File::get($file))) {
        $entry = new FileEntry;            
        $project_id = Project::find($id);
        $entry->project_id = $project_id;
        $entry->filename = $filename;
        $entry->mime = $file->getClientMimeType();
        $entry->path = $path;
        $entry->size = $file->getClientSize();
        $entry->save(); 
        return response([
                'status' => true,
                'msg' => 'A file has been saved!'
            ]);
    }
    return response()->json([
        'success' => false
    ], 500);
}

}

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.