I am searching for a way for creating database by my models structure in Laravel 5.5.
I know many Orm Like Doctorin Or ActiveRecord has this feature and so some micro Orm such as redbean has this feature but I cannot find a good reference for this ability in eloquent ORM of Laravel and if there is any method has it migrations which alter my existing database according to my model changes?
Related
There is a way (also presented here) to have create Eloquent ORM Models (as a part of a Laravel app) based on a database.
I am looking for the inverse action. I would like to write some Eloquent Model classes
and have them being craeted as tables in the database.
How can this be done?
This Eloquent documentation does not feature any information. Can it be that while there is a often the case 1-to-1-mapping between the database and the eleoquent models a table canno tbe created automatically given a Eloquent Model was provided?
For a project at work I'm creating an API in Laravel. I wanted to use MongoDB as database driver which is new to me. So I want to use Eloquent with MySQL in the beginning and when I'm confident enough switch to MongoDB.
I was reading some tutorials about the repository pattern in Laravel and saw that some returned an eloquent model, like this one. It seems to me that when returning a model on for example create($data), you're limited to database drivers which are suitable with Eloquent. I was wondering if it is a good practice to return an eloquent model. Because if I want to use MySQL for now and in the future MongoDB (without the Laravel MongoDB package), I need to rewrite some code in the controllers because the use the eloquent models instead of an array (for example). Maybe a 'wrapper' between the model and your code is a possibility? Any good recommendations, tips or thoughts on this?
If you're wondering why I want to use MySQL for now and later switch to MongoDB, the reason is there is a time limit on the project. I'm still learning Mongo. So to fulfil the needs of my employer, I'm not using MongoDB until finishing the first version / prototype.
If you use eloquent and its methods, you should be good. Just do not use the DB::raw() method as it may break your query if it does not match the DB engine you are currently in.
I wrote a repository pattern article if you want to look at it (with tdd).
But if you really want future proof, you can mix Doctrine w Laravel since Doctrine is a Data Mapper Pattern. Link
With laravel-doctrine package, you persist the data in your db engine that you prefer.
Is something like laravel-mongodb good?
Extending Eloquent to use MongoDB instead of MySQL.
In my Laravel 4.2 app I have several models of which use Eloquent ORM. I usually access the data through the standard functions (e.g. ::get()).
The issue I have is that with ORM I'm producing lots of queries when perhaps just a single custom query would suffice.
My question is, is there a way to execute a custom query but have those results populate into the my pre-existing Eloquent models.
Is there an easy way to fetch db metadata from laravel?
I was looking to leverage Breezejs EntityManager, but I need to fetch the metadata on my DB and I was hoping I wouldn't have to define this twice.
Update
specifically, I'm looking to acquire schema metadata about entity structure
http://www.breezejs.com/documentation/metadata-by-hand
http://json-schema.org/examples.html
There's not direct method, but if you are curious and don't mind using DataMapper instead of ActiveRecord (switching from Eloquent to Doctrine) there's this repo that leverages support for BreezeJS generating the entity metadata from Doctrine ORM annotated models. They implemented an Employee Directory sample app, that can have laravel as one of the server variations.
I'm writing the metadata by hand for now (it's really not complicated), You can also write some code that can infer the models schema by parsing some query like 'DESCRIBE table_name' so you can stick with Eloquent.
EDIT: The answer to this question shows this DESCRIBE approach Can Eloquent models retrieve metadata on their rows?
Does anyone know if Laravel has some sort of library/plugin or tweak to use Data Mapper or to make Active Record behave like Data Mapper?.
I'm not a Laravel user,so perhaps Eloquent is using a mix of Active Record and Data Mapper and I'm not aware of that.
So, we can implement the Data Mapper pattern into Laravel using Doctrine;
Packagist: https://packagist.org/packages/atrauzzi/laravel-doctrine
Laravel Doc: http://bundles.laravel.com/bundle/doctrine