Eloquent不会在请求创建中引用字符串

问题描述 投票:0回答:1

我希望你可以帮助我,因为我真的很接近用usb线缆自己;)

所以,我的问题非常“简单”:当我尝试创建一个要在我的数据库中插入的新对象时,Eloquent不会引用字符串类型属性。我知道,这很奇怪。

我给你一些代码。

这是我的模特:

class Ue extends Model
{

    protected $fillable = [
        'nomUe',
        'idUser',
    ];
}

在这里,我的功能:

public function addNewUe(Request $request){

    $ue = Ue::create($request->all());
    return response()->json($ue, 201);
}

我的控制者:Route::post('/ue', 'UeController@addNewUe');

然后,我的迁移:

public function up()
{
    Schema::create('ues', function (Blueprint $table) {
        $table->increments('id');
        $table->string('nomUe');
        $table->integer('idUser')->unsigned();
        $table->foreign('idUser')->references('id')->on('users');
        $table->timestamps();
    });
}

这是我得到的错误:

"SQLSTATE[HY000] [2002] No such file or directory (SQL: insert into `ues` (`nomUe`, `idUser`, `updated_at`, `created_at`) values (test, 1, 2018-03-05 17:05:22, 2018-03-05 17:05:22))"

为了测试我的请求,我在这里使用postman,pic:https://imgur.com/a/5Trvj

如您所见,未引用价值测试。你知道吗?我希望你能帮助我,所以提前感谢你的帮助,对不起我的英语不好

php mysql laravel laravel-5
1个回答
0
投票

好的,为了解决我在本地环境中的问题,我只需重启我的应用程序的artisan服务。当你重新启动它时,一切都会恢复。要运行服务,只需运行:php artisan serve

谢谢你的帮助;)

© www.soinside.com 2019 - 2024. All rights reserved.