'How to insert data in the enum field?

I've an enum field in my migration. The code is here:

 Schema::create('clients', function (Blueprint $table) {
        $table->increments('id');
        $table->string('title');
        $table->string('preview_img');
        $table->enum('platform', ['android', 'ios']);
        $table->integer('sort')->default(0)->nullable();
        $table->timestamps();
    });

I'm trying to insert the following data in the enum: enter image description here

I've the protected $fillable = ['platform']; in the Client model. But as the result I see the following: enter image description here

Where is my mistake? I've tried this variant:

 $platform = '';
    foreach ($request->platform as $p) {
        $platform .= $p . ',';
    }
    $platform = rtrim($platform, ',');
    $client->platform = $platform;

But it does not work too.



Solution 1:[1]

You are receiving a array on your $request->platform . Make sure you send just one option to your controller, this way:

In your view:

<select name='platform'>
  <option value="android">Android</option>
  <option value="ios">Ios</option>
</select>

In your controller:

$client->platform = $request->platform

If this don't work, please put this on your code dd($request->platform) and then show us

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Piazzi