php artisan tinker laravel PHP 致命错误:调用未定义的方法 stdClass::save() 管理员用户
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35336909/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
php artisan tinker laravel PHP Fatal error: Call to undefined method stdClass::save() admin user
提问by rabab hussein
First I have created an admin user using tinker then I deleted my migration in laravel5.1 then I did migration but this is the error:
首先,我使用 tinker 创建了一个管理员用户,然后我在 laravel5.1 中删除了我的迁移,然后我进行了迁移,但这是错误:
PHP Fatal error: Call to undefined method stdClass::save() in /var/www/myblog/vendor/psy/psysh/src/Psy/ExecutionLoop/Loop.php(76) : eval()'d code on line 1
[Symfony\Component\Debug\Exception\FatalErrorException]
Call to undefined method stdClass::save()
PHP 致命错误:调用 /var/www/myblog/vendor/psy/psysh/src/Psy/ExecutionLoop/Loop.php(76) 中未定义的方法 stdClass::save() :第 1 行的 eval() 代码
[Symfony\Component\Debug\Exception\FatalErrorException]
调用未定义的方法 stdClass::save()
回答by lagbox
You created a default object from an empty value, which PHP is warning you about. So PHP created an object and assigned a value to a property. For the most part you got this:
您从一个空值创建了一个默认对象,PHP 正在警告您。所以 PHP 创建了一个对象并为一个属性赋值。在大多数情况下,你得到了这个:
$user = new stdClass;
$user->name = 'admin2';
In short you don't have an instance of a model, you have a stdClass object. This would give you a User model object:
简而言之,您没有模型的实例,而是有一个 stdClass 对象。这将为您提供一个 User 模型对象:
$user = new App\User;
回答by Goldman.Vahdettin
Integer the id property from the admin user table.
You should test it that way.
你应该这样测试。
Schema::create('adminuser', function (Blueprint $table) {
$table->integer('id'); // this line
$table->string('title');
$table->text('description');
$table->timestamps();
});
回答by Avinash Raut
Created an object of model class and assign all values that want to be stored in table.
创建模型类的对象并分配要存储在表中的所有值。
>>> $User=new App\User; //create a object
=> App\User {#3026}
>>> $User->name="Avi";
=> "Avi"
>>> $User->created_at="2020-01-01";
=> "2020-01-01"
>>> $User->age="20";
=> "20"
>>> $User->body="this is an information";
=> "this is an information"
>>> $User->save();
=> true
>>>
Assigment values to the columns that can be changed as per your table columns.
将值分配给可以根据表列更改的列。