// Insert a new article record $article = [ 'title' => 'New article', 'content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 'author' => 'John Doe', 'created_at' => date('Y-m-d H:i:s') ]; // Insert article record into the database DB::table('articles')->insertOn($article);
// Insert a new user into the database $user = new User(); $user->name = 'Jane Doe'; $user->email = 'jane.doe@example.com'; $user->password = Hash::make('password'); $user->save(); // Insert a new article record $article = new Article(); $article->title = 'New article'; $article->content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; $article->author()->associate($user); $article->save();In this example, we create a new user and article record using the Eloquent ORM in Laravel. We first create a new user object and save it to the database. We then create a new article and associate it with the user using the "associate" method. Finally, we save the article to the database using the "save" method.