Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] Adding Additional Data? #1971

Closed
SeoRoman opened this issue Dec 21, 2018 · 3 comments
Closed

[QUESTION] Adding Additional Data? #1971

SeoRoman opened this issue Dec 21, 2018 · 3 comments

Comments

@SeoRoman
Copy link

SeoRoman commented Dec 21, 2018

Prerequisites

Versions

  • PHP version: 7.5.0
  • Laravel version: 5.6.33
  • Package version: 3.1

Description

Is there anyway to pass additional values of an array to the importable?

IE: If my spreadsheet has the following:

Users
ID,FNAME,LNAME
1,SEO,ROMAN
2,MAAT,EXCEL

and I want to import this file, but put them in the Group ID with an ID of 2

->postJson('/users/import', [ 'group_id' => 2, 'file' => $excel ]);

Now, the file works just fine and imports with 'group_id' being nullable, because it wasn't contained in the file... but is there anyway to inject 'group_id' => 2 into the importable so that it may be included automatically with the import?

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

@SeoRoman
Copy link
Author

SeoRoman commented Jan 8, 2019

Case Closed. Found answer with __construct()

@SeoRoman SeoRoman closed this as completed Jan 8, 2019
@yaofong
Copy link

yaofong commented Jan 11, 2019

Hi @SeoRoman may I know how do you achieve passing extra value to importable?
Thanks!

@kolyayurev
Copy link

class UsersImport implements ToModel
{
    use Importable;

    protected $data;

    public function __construct($data){
        $this->data = $data;
    }
}
...
(new UsersImport($request->data))->import($request->file);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants