Skip to content

A simple, proof-of-concept Laravel blog application powered by a MongoDB ORM.

Notifications You must be signed in to change notification settings

jpcaparas/mongoblog

Repository files navigation

Mongoblog

Laravel feat. MongoDB

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:

  1. Serve the application with php artisan serve or Valet.
  2. Seed the database with data fixtures by running php artisan migrate --seed.
  3. Get an overview of the api/v1 routes by running php artisan route:list.
  4. Download the Postman collection here and import the file into your Postman client.
  5. 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:
    'post_id' => 'in:posts,id'
    
    ... does not work, so I have to replace it with:
     '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() or app()->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.

About

A simple, proof-of-concept Laravel blog application powered by a MongoDB ORM.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages