updateOrCreate matching multiple attributes like company and record

Posted 2 years ago by eddieace

What I'm tring to do is adding records with the same title and company so that company one and two can have a record with the same title. I'v been trying to use the updateOrCreate method but with no success.

Here is my code, any clues?

$company_id = 12345;
$xml = simplexml_load_file($url);
$records = array();

foreach ($xml->channel as $x) {
    foreach ($x->item as $item) {
        $record[] = [
            'company_id' => $company_id,
            'title' => (string)$item->title,
            'location' => (string)$item->location,
            'description' => (string)$item->description,

foreach($records as $record) {
    Model::updateOrCreate(['title' => $record['title'], 'company_id' => $company_id], $record);

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

Reply to

Use Markdown with GitHub-flavored code blocks.