1

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.

Aleksej_Shherbak
  • 2,757
  • 5
  • 34
  • 71

1 Answers1

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

Piazzi
  • 2,490
  • 3
  • 11
  • 25
  • In my question I've a picture with the screen of xdebug session. It shows well what I have in the `$request->platform` https://i.stack.imgur.com/xbXyV.png – Aleksej_Shherbak Feb 28 '19 at 12:12
  • Well, this is strange, try this: ```$request->platform[0]``` im not sure why laravel recognize 'Android' as a array, but this should do the work. – Piazzi Feb 28 '19 at 12:14
  • Using `$request->platform[0]` might not be the best solution as it might always give Android option. It would be helpful if you add the view code that sends the request and `dd($request->platform)`. – Bharat Geleda Feb 28 '19 at 12:34