Search code examples
laravellaravel-excelimport-csv

import csv data with user details who uploading laravel-Excel


Here is my Import function

public function csv_import(Request $request){
    if (! Gate::allows('add')) {
        return abort(401);
    }

    // Increase Execution time
    ini_set('max_execution_time', 1200);

    request()->validate([
        'file'  => 'required|max:100240',
    ]);

    Excel::import(new CsvImport, request()->file('file'));

    return redirect()->route('admin.forms.create')->with(Session::flash('success', 'Your Data Has Been Successfully Uploaded'));
}

Solution

  •   I am not sure with your question. But, If you want to know all activities who created or updated your data into database you can use it with bootable that allow you track action.
    
    public static function boot()
    {
    
        parent::boot();
    
        // create a event to happen on updating
        static::updating(function ($table) {
            $table->updated_by = Auth::user()->id;
        });
    
        // create a event to happen on saving
        static::saving(function ($table) {
            $table->created_by = Auth::user()->id;
        });
    }