How to add a menu link to a menu programmatically? I want to add a menu link to a menu programmatically. Here is my code

MenuLinkContent::create([
      'title' =&gt; 'Example link',
      'link' =&gt; ['uri' =&gt; 'internal:/node'],
      'menu_name' =&gt; 'main',
    ])-&gt;save();


But it gives me the following error

PHP Fatal error:  Call to a member function get() on a non-object in /var/www/drupal8/core/modules/menu_link_content/src/Plugin/Menu/MenuLinkContent.php on line 105


Is there any way to add menu links to a menu programmatically?
I was using the wrong namespace.
Use the following namespace

use Drupal\menu_link_content\Entity\MenuLinkContent;


and then the following code will work.

MenuLinkContent::create([
      'title' =&gt; 'Example link',
      'link' =&gt; ['uri' =&gt; 'internal:/node'],
      'menu_name' =&gt; 'main',
    ])-&gt;save();