How to use JenssegersMongodbEloquentModel instead of IlluminateDatabaseEloquentModel in php artisan...











up vote
1
down vote

favorite
1












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?










share|improve this question


























    up vote
    1
    down vote

    favorite
    1












    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?










    share|improve this question
























      up vote
      1
      down vote

      favorite
      1









      up vote
      1
      down vote

      favorite
      1






      1





      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?










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 9 at 9:01









      Simone Bernardi

      61




      61
























          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.






          share|improve this answer




























            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');
            });





            share|improve this answer

















            • 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













            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            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

























            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.






            share|improve this answer

























              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.






              share|improve this answer























                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.






                share|improve this answer












                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 9 at 9:13









                Matthew Daly

                5,91622759




                5,91622759
























                    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');
                    });





                    share|improve this answer

















                    • 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

















                    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');
                    });





                    share|improve this answer

















                    • 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















                    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');
                    });





                    share|improve this answer












                    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');
                    });






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    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
















                    • 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




















                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    How to pass form data using jquery Ajax to insert data in database?

                    National Museum of Racing and Hall of Fame

                    Guess what letter conforming each word