0

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'));
}
MartenCatcher
  • 2,713
  • 8
  • 26
  • 39
itxrahulsingh
  • 53
  • 1
  • 11

2 Answers2

0
  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;
    });
}
Sok Chanty
  • 1,678
  • 2
  • 12
  • 22
  • Add this function into your model. – Sok Chanty Oct 31 '19 at 07:14
  • I want when am upload CSV data into the database, so also update the user_id who uploaded the CSV data, with boot function am only able to update when create or update record but not on import – itxrahulsingh Oct 31 '19 at 08:46
  • @itxrahulsingh Which package you use for import data? If you are using MaatWebsite package. you can check by mapping your data and then pass it into your model. – Sok Chanty Nov 01 '19 at 02:54
  • Link: [https://docs.laravel-excel.com/3.1/imports/model.html] – Sok Chanty Nov 01 '19 at 03:01
  • Right am using MaatWebsite package and I want when the import records also update user_id who importing can you show how is it possible – itxrahulsingh Nov 01 '19 at 08:56
0

You can try this:

 $result = Excel::import(new CsvImport, request()->file('file'));
 check $result is success or fail
 $result is true then => update "user_id" field
 E.g  ImportModel->update(['user_id' => Auth::user()->id]);
Dino
  • 7,779
  • 12
  • 46
  • 85
thaiha
  • 1