Phpstorm 9 EAP Unique Method Not Found in Illuminate \ Support \ Fluent Class

I am working on a website project and I am using Laravel 5 and PHPStorm 9 EAP.

I created a migration and used this code $table->string('name')->unique();, and the IDE highlighted unique()and displayed the message Method "unique" not found in class Illuminate\Support\Fluent.

Here is my migration:

class CreateProductsTable extends Migration {

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('products', function(Blueprint $table)
    {
        $table->increments('id');
        $table->string('name')->unique();
        $table->timestamps();
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::drop('products');
}

}

How can I fix this problem?

+4
source share
3 answers

The call $table->integer('user_id')returns a new instance Illuminate\Support\Fluent. But the Fluent class does not provide a method unique(). Instead, it uses the magic PHP method __call. This is why PHPStorm complains.

1 - PHPStorm, unique() . PHPDoc vendor/laravel/framework/src/Illuminate/Support/Fluent.php PHPStorm, unique() :

/**
 * @method unique
 */
class Fluent implements ArrayAccess, Arrayable, Jsonable, JsonSerializable 
{
    // ...
}

/vendor/. / Laravel. - (https://github.com/illuminate/support/pull/25).

- Fluent:

Schema::create('products', function(Blueprint $table)
{
    $table->increments('id');
    $table->string('name');
    $table->unique('name');
    $table->timestamps();
});
+12

PHP (, _ide_helper.php), PHPStorm .

Fluent , PHPStorm, php:

<?php

namespace Illuminate\Support;

/**
 * @method Fluent first()
 * @method Fluent after($column)
 * @method Fluent change()
 * @method Fluent nullable()
 * @method Fluent unsigned()
 * @method Fluent unique()
 * @method Fluent index()
 * @method Fluent primary()
 * @method Fluent default($value)
 * @method Fluent onUpdate($value)
 * @method Fluent onDelete($value)
 * @method Fluent references($value)
 * @method Fluent on($value)
 */
class Fluent {}

, , IDE, .

+4

Updated Version for Laravel 5.5

Create a file in your road directory with a name like _ide_helper_custom.php and copy the following code into it:

<?php

namespace  {
    exit("This file should not be included, only analyzed by your IDE");
}

namespace Illuminate\Support {

    /**
     * @method Fluent first()
     * @method Fluent after($column)
     * @method Fluent change()
     * @method Fluent nullable()
     * @method Fluent unsigned()
     * @method Fluent unique()
     * @method Fluent index()
     * @method Fluent primary()
     * @method Fluent spatialIndex()
     * @method Fluent default($value)
     * @method Fluent onUpdate($value)
     * @method Fluent onDelete($value)
     * @method Fluent references($value)
     * @method Fluent on($value)
     * @method Fluent charset($value)
     * @method Fluent collation($value)
     * @method Fluent comment($value)
     * @method Fluent autoIncrement()
     * @method Fluent storedAs($value)
     * @method Fluent useCurrent()
     * @method Fluent virtualAs($value)
     */
    class Fluent {

    }

}

This will force PHP Storm to index the file and correctly suggest methods for chaining. Tested in PHP Storm 2017.3, but should work in all previous and, hopefully, future versions of the IDE.

0
source

All Articles