当我尝试将用户插入我的默认用户表时,我收到500错误,这可以在app / storage / logs目录中看到:
[2016-02-10 10:03:52] production.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to a member function connection() on a non-object' in /var/www/html/myproject/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:2922
Stack trace:
#0 [internal function]: Illuminate\Exception\Handler->handleShutdown()
#1 {main} [] []
这是什么主要原因,我该如何解决?
app.php
'providers' => array(
'Illuminate\Foundation\Providers\ArtisanServiceProvider',
'Illuminate\Auth\AuthServiceProvider',
'Illuminate\Cache\CacheServiceProvider',
'Illuminate\Session\CommandsServiceProvider',
'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider',
'Illuminate\Routing\ControllerServiceProvider',
'Illuminate\Cookie\CookieServiceProvider',
'Illuminate\Database\DatabaseServiceProvider',
'Illuminate\Encryption\EncryptionServiceProvider',
'Illuminate\Filesystem\FilesystemServiceProvider',
'Illuminate\Hashing\HashServiceProvider',
'Illuminate\Html\HtmlServiceProvider',
'Illuminate\Log\LogServiceProvider',
'Illuminate\Mail\MailServiceProvider',
'Illuminate\Database\MigrationServiceProvider',
'Illuminate\Pagination\PaginationServiceProvider',
'Illuminate\Queue\QueueServiceProvider',
'Illuminate\Redis\RedisServiceProvider',
'Illuminate\Remote\RemoteServiceProvider',
'Illuminate\Auth\Reminders\ReminderServiceProvider',
'Illuminate\Database\SeedServiceProvider',
'Illuminate\Session\SessionServiceProvider',
'Illuminate\Translation\TranslationServiceProvider',
'Illuminate\Validation\ValidationServiceProvider',
'Illuminate\View\ViewServiceProvider',
'Illuminate\Workbench\WorkbenchServiceProvider',
'Mews\Captcha\CaptchaServiceProvider',
'Yangqi\Htmldom\HtmldomServiceProvider',
'Maxxscho\LaravelTcpdf\LaravelTcpdfServiceProvider',
'Maatwebsite\Excel\ExcelServiceProvider',
),
Controller.php这样
$instance = new myModal;
$instance->user = Input::get('username');
$instance->password = Hash::make(Input::get('pw'));
$instance->user_name = Input::get('username');
$instance->user_e_mail = Input::get('usermail');
$instance->save();
routes.php文件
Route::post('insertuser/{year}/{user}', array(
'as' => 'insertuser',
'uses' => 'AdminController@insertUser'
));
--- ---更新
myModal.php
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
class myModal extends Eloquent implements UserInterface, RemindableInterface{
use UserTrait, RemindableTrait;
protected $table = 'user_table';
protected $primaryKey = 'primary_key';
public $timestamps = false;
protected $increments = 'primary_key';
protected $fillable = array(
'user'
'password'
'user_name'
'user_e_mail '
)
}
---更新2 --- 这导致我的控制器出现问题:
setlocale(LC_CTYPE, 'tr_TR.utf8');
所以,我改变了如下:
setlocale(LC_CTYPE, 'tr_TR.utf8');
//other stuff
setlocale(LC_ALL,"en_US.utf8");
问题解决了。
提前致谢。