1. Go to this page and download the library: Download julien-c/mongovel 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/ */
julien-c / mongovel example snippets
class Book extends MongovelModel
{
}
public function show($id)
{
$book = Book::findOne(new MongoId($id));
// Here, you can access the book's attributes like in Eloquent:
// $book->title, $book->reviews, etc.
// $book->id is a string representation of the object's MongoId.
// Let's say we're an API, so let's just send the object as JSON:
return $book;
}
public function store()
{
$book = Input::only('title', 'content');
Book::insert($book);
}
public function reviewStore($id)
{
$review = Input::all();
// You can leverage the full power of Mongo query operators:
Book::update(new MongoId($id),
array('$push' => array('reviews' => $reviews))
);
return Response::json(array('status' => 201), 201);
}
public function destroy($id)
{
Book::remove(new MongoId($id));
}
public function index()
{
$books = Book::find();
$books->each(function($book) {
// Do anything you would do on a Laravel Collection
});
return $books;
}