Creating a new collection entry

Hi

Can I ask for a bit of advice on how to make a new collection entry for an import script? Ive got the updating side of things working but I keep getting

"call to a member function save() on null" when creating

I've looked at

https://statamic.dev/extending/data

which just refers to ->etc..... and doesnt give a full example so I've got

        $entry=Entry::findBySlug('product-1', 'products');
        if (!$entry){
            $entry = Entry::make();
            $entry->set("title","product name");
            $entry->set("price",10.40);
            $entry->set("source","VENDOR1");
            $entry->save();
        }  

which gives the aforementioned error. I realise as a minimum I'm missing how to tell it that I'm creating a "products" collection entry and what blueprint to use and I assume it will auto create the slug?

Is there more complete documentation I'm missing or can someone point me in the right direction for getting a product created?

Many thanks.

Tony

>>>>>>> Unanswered <<<<<<<
2 Replies
2 Followers