lundi 5 mars 2018

Eloquent don't quote string in request creation

I hope you can help me, because I'm really close to hand myself with an usb cable ;)

So, my problem is very "simple": When I try to create a new object to insert in my database, Eloquent don't quote the string type attribute. I know, it's strange.

I put you some code.

This is my model:

class Ue extends Model
{

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

here, my function:

public function addNewUe(Request $request){

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

my controller: Route::post('/ue', 'UeController@addNewUe');

and then, my migration:

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();
    });
}

This is the error I get:

"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))"

To test my request, I use postman, pic here: https://imgur.com/a/5Trvj

As you can see, the value test is not quoted. Have you any idea ? I hope you can help me, so thanks in advance for your help, and sorry for my bad english



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2FibJn2
via IFTTT

Aucun commentaire:

Enregistrer un commentaire