php artisan tinker laravel PHP致命错误:调用未定义的方法stdClass :: save()admin用户

时间:2016-02-11 10:35:46

标签: php laravel laravel-5.1

首先我使用tinker创建了一个管理员用户,然后我在laravel5.1中删除了我的迁移,然后我进行了迁移,但这是错误:

  

PHP致命错误:在/var/www/myblog/vendor/psy/psysh/src/Psy/ExecutionLoop/Loop.php(76)中调用未定义的方法stdClass :: save():eval()&#39 ;第1行的代码

     

[Symfony的\元器件\调试\异常\ FatalErrorException]
    调用未定义的方法stdClass :: save()

enter image description here

3 个答案:

答案 0 :(得分:7)

您从空值创建了一个默认对象,PHP正在向您发出警告。因此PHP创建了一个对象并为属性赋值。在大多数情况下,你得到了这个:

$user = new stdClass;
$user->name = 'admin2';

简而言之,你没有模型的实例,你有一个stdClass对象。这将为您提供User模型对象:

$user = new App\User;

答案 1 :(得分:0)

Integer the id property from the admin user table.

您应该以这种方式进行测试。

Schema::create('adminuser', function (Blueprint $table) {
            $table->integer('id'); // this line
            $table->string('title');
            $table->text('description');
            $table->timestamps();
        });

答案 2 :(得分:0)

创建了模型类的对象,并分配了要存储在表中的所有值。

>>> $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
>>> 

为可根据您的表列更改的列分配值。