--level 5:<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateBooksTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('books', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->foreignId('author_id')->constrained()->onDelete('cascade'); // <-- HERE
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('books', function (Blueprint $table) {
$table->dropForeign(['author_id']);
$table->drop();
});
}
}
Result of runing ./vendor/bin/phpstan analyse:
------ --------------------------------------------------------------------
Line database\migrations\2020_11_02_133706_create_books_table.php
------ --------------------------------------------------------------------
19 Call to an undefined method Illuminate\Support\Fluent::onDelete().
------ --------------------------------------------------------------------
How can I override that the return type of method foreignId()->constrained() is not Fluent, but ForeignIdColumnDefinition instead?
Yes, this is a known thing.
How can I override that the return type of method
foreignId()->constrained()is notFluent, butForeignIdColumnDefinitioninstead?
/** @var ForeignIdColumnDefinition $definition */
$definition = $table->foreignId('author_id')->constrained();
$definition->onDelete('cascade');
Thanks!
You're welcome.
@canvural Do we plan to support the constrained() method?
I think it's more about adding support for Illuminate\Support\Fluent
I don't have any plans, but if someone wants to implement it I will accept a PR! :+1:
I started seeing the following errors after updating my dependencies today.
Call to an undefined method Illuminate\Database\Eloquent\Relations\HasMany::first().
Call to an undefined method Illuminate\Database\Eloquent\Relations\HasMany::count().
Call to an undefined method Illuminate\Database\Eloquent\Relations\HasMany::where().
etc.
Is this the same problem as OP?
@PHLAK Your issue unrelated to the OP. Yours is related to issues like #824 #804 I think you can find the solution there, if not open a new issue.
Thanks @canvural, that was what I needed.
Most helpful comment