PHP code example of rosamarsky / laravel-doctrine-odm
1. Go to this page and download the library: Download rosamarsky/laravel-doctrine-odm library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rosamarsky / laravel-doctrine-odm example snippets
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
/** @ODM\Document(collection="users") */
class User {
/** @ODM\Id() */
private string $id;
/** @ODM\Field(type="string") */
private string $name;
/** @ODM\Field(type="string") */
private string $email;
/** @ODM\Field(type="carbon") */
private Carbon $createdAt;
public function __construct(string $name, string $email) {
$this->name = $name;
$this->email = $email;
}
}
class UserController extends AbstractController {
private $manager;
public function __construct(\Doctrine\ODM\MongoDB\DocumentManager $manager)
{
$this->manager = $manager;
}
public function store(Request $request): User
{
$user = new User('Roman Samarsky', '[email protected]');
$this->manager->persist($user);
$this->manager->flush();
return $user;
}
}