3 weeks ago

Inserting id where import value match username

Posted 3 weeks ago by devionti

So I have this excel sheet that only has username of users and I am going to import this data to another table called import

This is the import, I am using laravel excel User_id is a foreign key that references id in users

 return new Occupants([
  'user_id' => $this->transformUsernameToUserid($row[3]),

This function is supposed to compare the value in the excel sheet row with username in users table and then grab that id and it is the value of user_id

   public function transformUsernameToUserid($value)
    $query = DB::table('users')
    ->where('username', '=', $value)
   // ->toArray()
if($value == null){
    return null;
    return $query;

I get no error but it returns null

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