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.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.