CodeIgniter Eloquent Model Relationship Class Model Not Found










1















i'm trying to implement eloquent into my CodeIgniter project.



It works good when i call a model in my project (it give me data from my database). But when i'm trying to call relation for its model, it's went wrong and show this message:



An uncaught Exception was encountered
Type: Error

Message: Class 'applicationmodelsProfile' not found

Filename: /var/www/public/chupspace-git/vendor/illuminate/database/Eloquent/Model.php

Line Number: 750

Backtrace:

File: /var/www/public/chupspace-git/application/models/User.php
Line: 12
Function: hasOne

File: /var/www/public/chupspace-git/vendor/illuminate/database/Eloquent/Model.php
Line: 2638
Function: profile

File: /var/www/public/chupspace-git/vendor/illuminate/database/Eloquent/Model.php
Line: 2573
Function: getRelationshipFromMethod

File: /var/www/public/chupspace-git/vendor/illuminate/database/Eloquent/Model.php
Line: 3263
Function: getAttribute

File: /var/www/public/chupspace-git/application/controllers/UserController.php
Line: 53
Function: __get

File: /var/www/public/chupspace-git/index.php
Line: 357
Function: require_once


I use "illuminate/database": "5.0.28", library in my composer.json



Here is my model



User.php



if (!defined('BASEPATH')) exit('No direct script access allowed');

use IlluminateDatabaseEloquentModel as Eloquent;

class User extends Eloquent
protected $table = "users";

public function profile()

return $this->hasOne('applicationmodelsProfile');




Profile.php



if (!defined('BASEPATH')) exit('No direct script access allowed');

use IlluminateDatabaseEloquentModel as Eloquent;

class Profile extends Eloquent
protected $table = "user_profiles";



And here is my directory map.



enter image description here



Let me know if there is missing of information, so i can update this thread.
Your help is very valuable to me. Thanks.










share|improve this question






















  • just out of curiosity... why (besides the standard IT response "because I can") go through all the hoops of making Eloquent (an ORM/ActiveRecord implementation that is part of Laravel, an entirely different PHP framework) when CodeIgniter has its own ActiveRecord implementation built-in and working out of the box? just wondering....

    – Javier Larroulet
    Nov 13 '18 at 13:51











  • @Javier one of the most troublemaking things in Codeigniter is the missing part how to structure related data through connections - Eloquent is able to define relations - CI's QueryBuilder isn't. I posted a thread related to this topic a couple weeks ago forum.codeigniter.com/thread-71733.html

    – sintakonte
    Nov 13 '18 at 14:17















1















i'm trying to implement eloquent into my CodeIgniter project.



It works good when i call a model in my project (it give me data from my database). But when i'm trying to call relation for its model, it's went wrong and show this message:



An uncaught Exception was encountered
Type: Error

Message: Class 'applicationmodelsProfile' not found

Filename: /var/www/public/chupspace-git/vendor/illuminate/database/Eloquent/Model.php

Line Number: 750

Backtrace:

File: /var/www/public/chupspace-git/application/models/User.php
Line: 12
Function: hasOne

File: /var/www/public/chupspace-git/vendor/illuminate/database/Eloquent/Model.php
Line: 2638
Function: profile

File: /var/www/public/chupspace-git/vendor/illuminate/database/Eloquent/Model.php
Line: 2573
Function: getRelationshipFromMethod

File: /var/www/public/chupspace-git/vendor/illuminate/database/Eloquent/Model.php
Line: 3263
Function: getAttribute

File: /var/www/public/chupspace-git/application/controllers/UserController.php
Line: 53
Function: __get

File: /var/www/public/chupspace-git/index.php
Line: 357
Function: require_once


I use "illuminate/database": "5.0.28", library in my composer.json



Here is my model



User.php



if (!defined('BASEPATH')) exit('No direct script access allowed');

use IlluminateDatabaseEloquentModel as Eloquent;

class User extends Eloquent
protected $table = "users";

public function profile()

return $this->hasOne('applicationmodelsProfile');




Profile.php



if (!defined('BASEPATH')) exit('No direct script access allowed');

use IlluminateDatabaseEloquentModel as Eloquent;

class Profile extends Eloquent
protected $table = "user_profiles";



And here is my directory map.



enter image description here



Let me know if there is missing of information, so i can update this thread.
Your help is very valuable to me. Thanks.










share|improve this question






















  • just out of curiosity... why (besides the standard IT response "because I can") go through all the hoops of making Eloquent (an ORM/ActiveRecord implementation that is part of Laravel, an entirely different PHP framework) when CodeIgniter has its own ActiveRecord implementation built-in and working out of the box? just wondering....

    – Javier Larroulet
    Nov 13 '18 at 13:51











  • @Javier one of the most troublemaking things in Codeigniter is the missing part how to structure related data through connections - Eloquent is able to define relations - CI's QueryBuilder isn't. I posted a thread related to this topic a couple weeks ago forum.codeigniter.com/thread-71733.html

    – sintakonte
    Nov 13 '18 at 14:17













1












1








1


1






i'm trying to implement eloquent into my CodeIgniter project.



It works good when i call a model in my project (it give me data from my database). But when i'm trying to call relation for its model, it's went wrong and show this message:



An uncaught Exception was encountered
Type: Error

Message: Class 'applicationmodelsProfile' not found

Filename: /var/www/public/chupspace-git/vendor/illuminate/database/Eloquent/Model.php

Line Number: 750

Backtrace:

File: /var/www/public/chupspace-git/application/models/User.php
Line: 12
Function: hasOne

File: /var/www/public/chupspace-git/vendor/illuminate/database/Eloquent/Model.php
Line: 2638
Function: profile

File: /var/www/public/chupspace-git/vendor/illuminate/database/Eloquent/Model.php
Line: 2573
Function: getRelationshipFromMethod

File: /var/www/public/chupspace-git/vendor/illuminate/database/Eloquent/Model.php
Line: 3263
Function: getAttribute

File: /var/www/public/chupspace-git/application/controllers/UserController.php
Line: 53
Function: __get

File: /var/www/public/chupspace-git/index.php
Line: 357
Function: require_once


I use "illuminate/database": "5.0.28", library in my composer.json



Here is my model



User.php



if (!defined('BASEPATH')) exit('No direct script access allowed');

use IlluminateDatabaseEloquentModel as Eloquent;

class User extends Eloquent
protected $table = "users";

public function profile()

return $this->hasOne('applicationmodelsProfile');




Profile.php



if (!defined('BASEPATH')) exit('No direct script access allowed');

use IlluminateDatabaseEloquentModel as Eloquent;

class Profile extends Eloquent
protected $table = "user_profiles";



And here is my directory map.



enter image description here



Let me know if there is missing of information, so i can update this thread.
Your help is very valuable to me. Thanks.










share|improve this question














i'm trying to implement eloquent into my CodeIgniter project.



It works good when i call a model in my project (it give me data from my database). But when i'm trying to call relation for its model, it's went wrong and show this message:



An uncaught Exception was encountered
Type: Error

Message: Class 'applicationmodelsProfile' not found

Filename: /var/www/public/chupspace-git/vendor/illuminate/database/Eloquent/Model.php

Line Number: 750

Backtrace:

File: /var/www/public/chupspace-git/application/models/User.php
Line: 12
Function: hasOne

File: /var/www/public/chupspace-git/vendor/illuminate/database/Eloquent/Model.php
Line: 2638
Function: profile

File: /var/www/public/chupspace-git/vendor/illuminate/database/Eloquent/Model.php
Line: 2573
Function: getRelationshipFromMethod

File: /var/www/public/chupspace-git/vendor/illuminate/database/Eloquent/Model.php
Line: 3263
Function: getAttribute

File: /var/www/public/chupspace-git/application/controllers/UserController.php
Line: 53
Function: __get

File: /var/www/public/chupspace-git/index.php
Line: 357
Function: require_once


I use "illuminate/database": "5.0.28", library in my composer.json



Here is my model



User.php



if (!defined('BASEPATH')) exit('No direct script access allowed');

use IlluminateDatabaseEloquentModel as Eloquent;

class User extends Eloquent
protected $table = "users";

public function profile()

return $this->hasOne('applicationmodelsProfile');




Profile.php



if (!defined('BASEPATH')) exit('No direct script access allowed');

use IlluminateDatabaseEloquentModel as Eloquent;

class Profile extends Eloquent
protected $table = "user_profiles";



And here is my directory map.



enter image description here



Let me know if there is missing of information, so i can update this thread.
Your help is very valuable to me. Thanks.







php codeigniter model eloquent relational-database






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 13:22









Miftah MizwarMiftah Mizwar

617510




617510












  • just out of curiosity... why (besides the standard IT response "because I can") go through all the hoops of making Eloquent (an ORM/ActiveRecord implementation that is part of Laravel, an entirely different PHP framework) when CodeIgniter has its own ActiveRecord implementation built-in and working out of the box? just wondering....

    – Javier Larroulet
    Nov 13 '18 at 13:51











  • @Javier one of the most troublemaking things in Codeigniter is the missing part how to structure related data through connections - Eloquent is able to define relations - CI's QueryBuilder isn't. I posted a thread related to this topic a couple weeks ago forum.codeigniter.com/thread-71733.html

    – sintakonte
    Nov 13 '18 at 14:17

















  • just out of curiosity... why (besides the standard IT response "because I can") go through all the hoops of making Eloquent (an ORM/ActiveRecord implementation that is part of Laravel, an entirely different PHP framework) when CodeIgniter has its own ActiveRecord implementation built-in and working out of the box? just wondering....

    – Javier Larroulet
    Nov 13 '18 at 13:51











  • @Javier one of the most troublemaking things in Codeigniter is the missing part how to structure related data through connections - Eloquent is able to define relations - CI's QueryBuilder isn't. I posted a thread related to this topic a couple weeks ago forum.codeigniter.com/thread-71733.html

    – sintakonte
    Nov 13 '18 at 14:17
















just out of curiosity... why (besides the standard IT response "because I can") go through all the hoops of making Eloquent (an ORM/ActiveRecord implementation that is part of Laravel, an entirely different PHP framework) when CodeIgniter has its own ActiveRecord implementation built-in and working out of the box? just wondering....

– Javier Larroulet
Nov 13 '18 at 13:51





just out of curiosity... why (besides the standard IT response "because I can") go through all the hoops of making Eloquent (an ORM/ActiveRecord implementation that is part of Laravel, an entirely different PHP framework) when CodeIgniter has its own ActiveRecord implementation built-in and working out of the box? just wondering....

– Javier Larroulet
Nov 13 '18 at 13:51













@Javier one of the most troublemaking things in Codeigniter is the missing part how to structure related data through connections - Eloquent is able to define relations - CI's QueryBuilder isn't. I posted a thread related to this topic a couple weeks ago forum.codeigniter.com/thread-71733.html

– sintakonte
Nov 13 '18 at 14:17





@Javier one of the most troublemaking things in Codeigniter is the missing part how to structure related data through connections - Eloquent is able to define relations - CI's QueryBuilder isn't. I posted a thread related to this topic a couple weeks ago forum.codeigniter.com/thread-71733.html

– sintakonte
Nov 13 '18 at 14:17












2 Answers
2






active

oldest

votes


















0














You need to load all relation class before use it.



First of all you need to enable in the application/config/config.php the composer autoload. Just set $config['composer_autoload'] to TRUE



Then you need to extend your composer.json to load every models:




"autoload":
"classmap": ["application/models/"]





Then you need to regenerate the autoload file (run in cli):



composer dump-autoload


It should be works. There is more other ways to do it, but i think it's the clearest.






share|improve this answer























  • Thank for your answer. I have done this part before, but the error still the same.

    – Miftah Mizwar
    Nov 13 '18 at 15:35


















0














I found the solution. We just need to change



$this->hasOne('applicationmodelsProfile');



to be



$this->hasOne(new Profile());



Here is my full code.



<?php

if (!defined('BASEPATH')) exit('No direct script access allowed');

use IlluminateDatabaseEloquentModel as Eloquent;

class User extends Eloquent
protected $table = "users";

public function profile()

// dd();
return $this->hasOne(new Profile());




It works good for me.






share|improve this answer






















    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',
    autoActivateHeartbeat: false,
    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%2f53281979%2fcodeigniter-eloquent-model-relationship-class-model-not-found%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









    0














    You need to load all relation class before use it.



    First of all you need to enable in the application/config/config.php the composer autoload. Just set $config['composer_autoload'] to TRUE



    Then you need to extend your composer.json to load every models:




    "autoload":
    "classmap": ["application/models/"]





    Then you need to regenerate the autoload file (run in cli):



    composer dump-autoload


    It should be works. There is more other ways to do it, but i think it's the clearest.






    share|improve this answer























    • Thank for your answer. I have done this part before, but the error still the same.

      – Miftah Mizwar
      Nov 13 '18 at 15:35















    0














    You need to load all relation class before use it.



    First of all you need to enable in the application/config/config.php the composer autoload. Just set $config['composer_autoload'] to TRUE



    Then you need to extend your composer.json to load every models:




    "autoload":
    "classmap": ["application/models/"]





    Then you need to regenerate the autoload file (run in cli):



    composer dump-autoload


    It should be works. There is more other ways to do it, but i think it's the clearest.






    share|improve this answer























    • Thank for your answer. I have done this part before, but the error still the same.

      – Miftah Mizwar
      Nov 13 '18 at 15:35













    0












    0








    0







    You need to load all relation class before use it.



    First of all you need to enable in the application/config/config.php the composer autoload. Just set $config['composer_autoload'] to TRUE



    Then you need to extend your composer.json to load every models:




    "autoload":
    "classmap": ["application/models/"]





    Then you need to regenerate the autoload file (run in cli):



    composer dump-autoload


    It should be works. There is more other ways to do it, but i think it's the clearest.






    share|improve this answer













    You need to load all relation class before use it.



    First of all you need to enable in the application/config/config.php the composer autoload. Just set $config['composer_autoload'] to TRUE



    Then you need to extend your composer.json to load every models:




    "autoload":
    "classmap": ["application/models/"]





    Then you need to regenerate the autoload file (run in cli):



    composer dump-autoload


    It should be works. There is more other ways to do it, but i think it's the clearest.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 13 '18 at 13:51









    ffffff

    534




    534












    • Thank for your answer. I have done this part before, but the error still the same.

      – Miftah Mizwar
      Nov 13 '18 at 15:35

















    • Thank for your answer. I have done this part before, but the error still the same.

      – Miftah Mizwar
      Nov 13 '18 at 15:35
















    Thank for your answer. I have done this part before, but the error still the same.

    – Miftah Mizwar
    Nov 13 '18 at 15:35





    Thank for your answer. I have done this part before, but the error still the same.

    – Miftah Mizwar
    Nov 13 '18 at 15:35













    0














    I found the solution. We just need to change



    $this->hasOne('applicationmodelsProfile');



    to be



    $this->hasOne(new Profile());



    Here is my full code.



    <?php

    if (!defined('BASEPATH')) exit('No direct script access allowed');

    use IlluminateDatabaseEloquentModel as Eloquent;

    class User extends Eloquent
    protected $table = "users";

    public function profile()

    // dd();
    return $this->hasOne(new Profile());




    It works good for me.






    share|improve this answer



























      0














      I found the solution. We just need to change



      $this->hasOne('applicationmodelsProfile');



      to be



      $this->hasOne(new Profile());



      Here is my full code.



      <?php

      if (!defined('BASEPATH')) exit('No direct script access allowed');

      use IlluminateDatabaseEloquentModel as Eloquent;

      class User extends Eloquent
      protected $table = "users";

      public function profile()

      // dd();
      return $this->hasOne(new Profile());




      It works good for me.






      share|improve this answer

























        0












        0








        0







        I found the solution. We just need to change



        $this->hasOne('applicationmodelsProfile');



        to be



        $this->hasOne(new Profile());



        Here is my full code.



        <?php

        if (!defined('BASEPATH')) exit('No direct script access allowed');

        use IlluminateDatabaseEloquentModel as Eloquent;

        class User extends Eloquent
        protected $table = "users";

        public function profile()

        // dd();
        return $this->hasOne(new Profile());




        It works good for me.






        share|improve this answer













        I found the solution. We just need to change



        $this->hasOne('applicationmodelsProfile');



        to be



        $this->hasOne(new Profile());



        Here is my full code.



        <?php

        if (!defined('BASEPATH')) exit('No direct script access allowed');

        use IlluminateDatabaseEloquentModel as Eloquent;

        class User extends Eloquent
        protected $table = "users";

        public function profile()

        // dd();
        return $this->hasOne(new Profile());




        It works good for me.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 15:47









        Miftah MizwarMiftah Mizwar

        617510




        617510



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53281979%2fcodeigniter-eloquent-model-relationship-class-model-not-found%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

            Kleinkühnau

            Makov (Slowakei)

            Deutsches Schauspielhaus