Awesome
Mongoblog
A simple, proof-of-concept Laravel blog application powered by a MongoDB ORM.
Separated API and front-end
This is a RESTful application, whose API is entirely decoupled from its front-end (neat, eh?), meaning it is fully testable from a REST client like Postman or from PHPStorm's built-in client.
To test the API endpoints on Postman:
- Serve the application with
php artisan serve
or Valet. - Seed the database with data fixtures by running
php artisan migrate --seed
. - Get an overview of the
api/v1
routes by runningphp artisan route:list
. - Download the Postman collection here and import the file into your Postman client.
- Start testing (and remember to change environment variables as needed).
System requirements
- PHP v7.x
- MongoDB v3.4
- nginx 1.10 or PHP's built-in web server
Gotchas
I'm having issues installing the
jenssegers/mongodb
package.
Run php -m | grep mongodb
to confirm that the MongoDB PHP extension is installed.
If the above does not work, run composer install --ignore-platform-reqs
.
I'm getting
Class 'MongoDB\Driver\Manager' not found
when I run the application
Restart your web server. It probably has not loaded the php-mongodb
extension yet.
Can I revert back to MySQL/SQLite without issue?
Unfortunately, as this library is not officially supported by Laravel, it comes with integration issues here and there, a few which are:
- The inability to drop tables using
dropIfExists
. - Missing polyfills on its drop-in Eloquent replacement.
- The inability to use a table's
id
column on the default query builder; you'll have to use_id
-- the convention with which MongoDB stores primary keys. This has given me problems with validation rules:
... does not work, so I have to replace it with:'post_id' => 'in:posts,id'
'post_id' => 'in:posts,_id'
I initially wanted to test polymorphic relationships with the Category
and Comment
models, but just went with a many-to-many due to the lack of documentation.
Why aren't you using
Route::dispatch()
orapp()->handle()
to consume internal API endpoints?
Taylor Otwell advises against using sub-requests to make internal API calls, as they mess the current route. I went with this kitetail/zttp
package by Adam Wathan that leverages Guzzle and I wrapped it within a trait.
Features & suggestions
View the Projects page for a roadmap of things to come.
If you come across a bug, feel free to open a new issue. For a bug specific to the MongoDB ORM, submit a ticket via their GitHub page.
To-do
- Authentication
- Integration tests
- Front-end / templates
For a comprehensive list of to-dos for the core functionality of the application, visit the Core features project page.