Laravel/Eloquent: Fatal error: Call to a member function connection() on a non-object

后端 未结 5 1102
长发绾君心
长发绾君心 2021-02-13 12:06

I\'m building a package in Laravel 4 but am getting a non-object error when attempting to access the db from which seems to be a properly instantiated object. Here\'s the setup:

5条回答
  •  别跟我提以往
    2021-02-13 12:46

    Try including the DB facade as well as Eloquent...

    use Illuminate\Support\Facades\DB;
    use Illuminate\Database\Eloquent\Model as Eloquent;
    

    ...and then see if you have access to DB::table('chat_history').

    (Also note that in your class, your call to use Illuminate\Database\Model; should be Illuminate\Database\Eloquent\Model; )

提交回复
热议问题