DEV Community

IRAWAN
IRAWAN

Posted on

How to pass user_id for importing excel using Laravel?

So what you can do is

public function model(array $row)
{    
    $user = auth()->user();  //Get the current user 
    return new Supplier([
        'name' =>$row[0],
        'phone' =>$row[1],
        'email' =>$row[2],
        'address' =>$row[3],
        'city' =>$row[4],
        'country' =>$row[5],
        'customer' =>$row[6],
        'user_id'=> $user->id,      // add their user id when importing    
        
    ]);

Top comments (0)