Support the ongoing development of Laravel.io →
posted 9 years ago
Database
Last updated 2 years ago.
0

try

 $table->unsignedInteger('project_id');  
0

Thanks, jweultjes, but that's not the real issue I'm struggling with.

Both integer($name, $unsigned) and unsignedInteger($name) give the same results, the issue is that they don't seem to match, or chain as per the 5.0 docs and the tutorial example.

I know Laravel is heavy on the facades, but I created the migration using Artisan, so I don't understand - it should be pointing to the correct classes.

Last updated 9 years ago.
0

I'm having the same issue as you that sometimes the ide_helper doesn't seem to auto complete as much as you'd like. And I also agree that the documentation seems to be lacking in listing possibilities.

0

OK, I figured it out.

The Fluent instance that is returned sets attributes on itself via magic methods, therefore all the methods outlined in the docs don't actually exist as physical methods on the class.

Instead, Laravel is magically setting values on the Fluent instance, as per the method name and passed values:

public function __call($method, $parameters)
{
	$this->attributes[$method] = count($parameters) > 0 ? $parameters[0] : true;

	return $this;
}

It's a real shame this isn't mentioned in the docs! It would certainly help to demystify the framework (and would save me from some head scratching).

Furthermore, confusion could be avoided for IDEs that support them (PHPStorm does) by using PHPDoc @method parameters on the class itself:

/**
 * Class Fluent
 * @package Illuminate\Support
 *
 * @method Fluent default() default(mixed $value) Declare a default value for a column
 */

This then shows the correct autocomplete in the IDE, without the need for hacks.

Last updated 9 years ago.
0

For anyone who would like to add these methods using PHPDoc, just copy this block to the top of your Fluent file:

// copy to 'vendor\laravel\framework\src\Illuminate\Support\Fluent.php'

/**
 * Class Fluent
 * @package Illuminate\Support
 *
 * @see http://laravel.com/docs/master/schema
 *
 * @method Fluent unsigned() 	                Set INTEGER to UNSIGNED
 * @method Fluent nullable()                    Designate that the column allows NULL values
 * @method Fluent default(mixed $value)         Declare a default value for a column
 *
 * @method Fluent references(string $key)       Specifies the name of the foreign key constraint
 * @method Fluent on(string $table)             Specifies the table on which the constraint applies to
 * @method Fluent onDelete(string $action) 	    Specifies the action to happen on a DELETE
 * @method Fluent onUpdate(string $action) 	    Specifies the action to happen on an UPDATE
 */

You'll then get completions in PHPStorm like so:

Laravel Schema Builder completions in PHPStorm

If there's a better way to do this (perhaps by way of the original ide helper file) I would be glad to know.

Last updated 9 years ago.
0

OK, so I've done some reading up about Fluent, and I now understand that Fluent is essentially only a utility class, and not specifically a class to aid with database abstraction.

As such, the PHPDoc above doesn't make sense from the point of the Fluent class itself, even though it does from the point of view of a migration.

Of course, I don't know very much about Laravel yet, but it would seem from an OO perspective, that instead of returning a Fluent instance from Blueprint::addColumn(), it might be nice to return a Fluent subclass, perhaps Schema\Column with the magic methods DocCommented.

That would certainly aid with autocomplete, though I see now that this really is only a very small part of the functionality of the overall framework, and looks like it is only used in migrations, so it's not the end of the world if it doesn't happen.

From a quick search of the source code, it looks like new Fluent is only used 4 times, in Blueprint, Validator and CapsuleManagerTrait, so it seems like it could be done fairly easily.

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.