How to use JenssegersMongodbEloquentModel instead of IlluminateDatabaseEloquentModel in php artisan...
up vote
1
down vote
favorite
I'm developing a webapp with Laravel and MongoDB (jenssegers/laravel-mongodb).
While creating a new model with php artisan make:model, the command uses IlluminateDatabaseEloquentModel declaration in the file and every time I need to replace IlluminateDatabaseEloquentModel with JenssegersMongodbEloquentModel manually.
Is there a way to automate the process?
php mongodb laravel eloquent
add a comment |
up vote
1
down vote
favorite
I'm developing a webapp with Laravel and MongoDB (jenssegers/laravel-mongodb).
While creating a new model with php artisan make:model, the command uses IlluminateDatabaseEloquentModel declaration in the file and every time I need to replace IlluminateDatabaseEloquentModel with JenssegersMongodbEloquentModel manually.
Is there a way to automate the process?
php mongodb laravel eloquent
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm developing a webapp with Laravel and MongoDB (jenssegers/laravel-mongodb).
While creating a new model with php artisan make:model, the command uses IlluminateDatabaseEloquentModel declaration in the file and every time I need to replace IlluminateDatabaseEloquentModel with JenssegersMongodbEloquentModel manually.
Is there a way to automate the process?
php mongodb laravel eloquent
I'm developing a webapp with Laravel and MongoDB (jenssegers/laravel-mongodb).
While creating a new model with php artisan make:model, the command uses IlluminateDatabaseEloquentModel declaration in the file and every time I need to replace IlluminateDatabaseEloquentModel with JenssegersMongodbEloquentModel manually.
Is there a way to automate the process?
php mongodb laravel eloquent
php mongodb laravel eloquent
asked Nov 9 at 9:01
Simone Bernardi
61
61
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
It doesn't look like the package provides an Artisan command to create a MongoDB model stub, which seems like a bit of an oversight. However, it's not terribly hard to create this kind of generator command for Artisan yourself if you need it.
The model make command is at https://github.com/laravel/framework/blob/5.7/src/Illuminate/Foundation/Console/ModelMakeCommand.php and the stub file used to create it is at https://github.com/laravel/framework/blob/5.7/src/Illuminate/Foundation/Console/stubs/model.stub. If you extend the command class to replace the stub file with your MongoDB version, and amend the stub file to be a MongoDB model, then you should be able to create a command for generating MongoDB models. It might even be worth forking the package to add this and submitting a pull request to get it added to the package. I would refer to the part of the Laravel documentation that deals with Artisan for more details, as that describes the process of adding your own Artisan commands in detail.
add a comment |
up vote
1
down vote
Another approach would be to write your own class generator and then overwrite the command make:model
Add the following in the file routes/console.php to override the command
use PathToClassMyCustomClassGenerator;
Artisan::command('make:model', function(){
new MyCustomClassGenerator();
$this->comment('new MongoDB Model generated');
});
1
The trouble with that is of course if you want to use MongoDB alongside a relational database, it stops the normal command from being any use. In all fairness, it's quite rare to use both together (although the only time I've used MongoDB with Laravel was on a project I inherited that did just that).
– Matthew Daly
Nov 9 at 9:48
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
It doesn't look like the package provides an Artisan command to create a MongoDB model stub, which seems like a bit of an oversight. However, it's not terribly hard to create this kind of generator command for Artisan yourself if you need it.
The model make command is at https://github.com/laravel/framework/blob/5.7/src/Illuminate/Foundation/Console/ModelMakeCommand.php and the stub file used to create it is at https://github.com/laravel/framework/blob/5.7/src/Illuminate/Foundation/Console/stubs/model.stub. If you extend the command class to replace the stub file with your MongoDB version, and amend the stub file to be a MongoDB model, then you should be able to create a command for generating MongoDB models. It might even be worth forking the package to add this and submitting a pull request to get it added to the package. I would refer to the part of the Laravel documentation that deals with Artisan for more details, as that describes the process of adding your own Artisan commands in detail.
add a comment |
up vote
1
down vote
It doesn't look like the package provides an Artisan command to create a MongoDB model stub, which seems like a bit of an oversight. However, it's not terribly hard to create this kind of generator command for Artisan yourself if you need it.
The model make command is at https://github.com/laravel/framework/blob/5.7/src/Illuminate/Foundation/Console/ModelMakeCommand.php and the stub file used to create it is at https://github.com/laravel/framework/blob/5.7/src/Illuminate/Foundation/Console/stubs/model.stub. If you extend the command class to replace the stub file with your MongoDB version, and amend the stub file to be a MongoDB model, then you should be able to create a command for generating MongoDB models. It might even be worth forking the package to add this and submitting a pull request to get it added to the package. I would refer to the part of the Laravel documentation that deals with Artisan for more details, as that describes the process of adding your own Artisan commands in detail.
add a comment |
up vote
1
down vote
up vote
1
down vote
It doesn't look like the package provides an Artisan command to create a MongoDB model stub, which seems like a bit of an oversight. However, it's not terribly hard to create this kind of generator command for Artisan yourself if you need it.
The model make command is at https://github.com/laravel/framework/blob/5.7/src/Illuminate/Foundation/Console/ModelMakeCommand.php and the stub file used to create it is at https://github.com/laravel/framework/blob/5.7/src/Illuminate/Foundation/Console/stubs/model.stub. If you extend the command class to replace the stub file with your MongoDB version, and amend the stub file to be a MongoDB model, then you should be able to create a command for generating MongoDB models. It might even be worth forking the package to add this and submitting a pull request to get it added to the package. I would refer to the part of the Laravel documentation that deals with Artisan for more details, as that describes the process of adding your own Artisan commands in detail.
It doesn't look like the package provides an Artisan command to create a MongoDB model stub, which seems like a bit of an oversight. However, it's not terribly hard to create this kind of generator command for Artisan yourself if you need it.
The model make command is at https://github.com/laravel/framework/blob/5.7/src/Illuminate/Foundation/Console/ModelMakeCommand.php and the stub file used to create it is at https://github.com/laravel/framework/blob/5.7/src/Illuminate/Foundation/Console/stubs/model.stub. If you extend the command class to replace the stub file with your MongoDB version, and amend the stub file to be a MongoDB model, then you should be able to create a command for generating MongoDB models. It might even be worth forking the package to add this and submitting a pull request to get it added to the package. I would refer to the part of the Laravel documentation that deals with Artisan for more details, as that describes the process of adding your own Artisan commands in detail.
answered Nov 9 at 9:13
Matthew Daly
5,91622759
5,91622759
add a comment |
add a comment |
up vote
1
down vote
Another approach would be to write your own class generator and then overwrite the command make:model
Add the following in the file routes/console.php to override the command
use PathToClassMyCustomClassGenerator;
Artisan::command('make:model', function(){
new MyCustomClassGenerator();
$this->comment('new MongoDB Model generated');
});
1
The trouble with that is of course if you want to use MongoDB alongside a relational database, it stops the normal command from being any use. In all fairness, it's quite rare to use both together (although the only time I've used MongoDB with Laravel was on a project I inherited that did just that).
– Matthew Daly
Nov 9 at 9:48
add a comment |
up vote
1
down vote
Another approach would be to write your own class generator and then overwrite the command make:model
Add the following in the file routes/console.php to override the command
use PathToClassMyCustomClassGenerator;
Artisan::command('make:model', function(){
new MyCustomClassGenerator();
$this->comment('new MongoDB Model generated');
});
1
The trouble with that is of course if you want to use MongoDB alongside a relational database, it stops the normal command from being any use. In all fairness, it's quite rare to use both together (although the only time I've used MongoDB with Laravel was on a project I inherited that did just that).
– Matthew Daly
Nov 9 at 9:48
add a comment |
up vote
1
down vote
up vote
1
down vote
Another approach would be to write your own class generator and then overwrite the command make:model
Add the following in the file routes/console.php to override the command
use PathToClassMyCustomClassGenerator;
Artisan::command('make:model', function(){
new MyCustomClassGenerator();
$this->comment('new MongoDB Model generated');
});
Another approach would be to write your own class generator and then overwrite the command make:model
Add the following in the file routes/console.php to override the command
use PathToClassMyCustomClassGenerator;
Artisan::command('make:model', function(){
new MyCustomClassGenerator();
$this->comment('new MongoDB Model generated');
});
answered Nov 9 at 9:33
Edwin Krause
1,016921
1,016921
1
The trouble with that is of course if you want to use MongoDB alongside a relational database, it stops the normal command from being any use. In all fairness, it's quite rare to use both together (although the only time I've used MongoDB with Laravel was on a project I inherited that did just that).
– Matthew Daly
Nov 9 at 9:48
add a comment |
1
The trouble with that is of course if you want to use MongoDB alongside a relational database, it stops the normal command from being any use. In all fairness, it's quite rare to use both together (although the only time I've used MongoDB with Laravel was on a project I inherited that did just that).
– Matthew Daly
Nov 9 at 9:48
1
1
The trouble with that is of course if you want to use MongoDB alongside a relational database, it stops the normal command from being any use. In all fairness, it's quite rare to use both together (although the only time I've used MongoDB with Laravel was on a project I inherited that did just that).
– Matthew Daly
Nov 9 at 9:48
The trouble with that is of course if you want to use MongoDB alongside a relational database, it stops the normal command from being any use. In all fairness, it's quite rare to use both together (although the only time I've used MongoDB with Laravel was on a project I inherited that did just that).
– Matthew Daly
Nov 9 at 9:48
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222613%2fhow-to-use-jenssegers-mongodb-eloquent-model-instead-of-illuminate-database-eloq%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown