提问人:Aismaili 提问时间:5/1/2023 最后编辑:RiggsFollyAismaili 更新时间:5/1/2023 访问量:36
BadMethodCallException (坏方法调用异常) |方法 Illuminate\Database\Schema\Blueprint::whereRaw 不存在
BadMethodCallException | Method Illuminate\Database\Schema\Blueprint::whereRaw does not exist
问:
在 Larevel 中,我无法迁移此表“收藏夹”,我遇到了这个错误
(方法 Illuminate\Database\Schema\Blueprint::whereRaw 不存在。
我试图使用“orWhere”和“where”来代替,但它是无用的,导致同样的错误......这是我的代码。
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateFavoritesTable extends Migration
{
/**
* Run the migrations.
*/
public function up()
{
Schema::create('favorites', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->enum('item_type', ['question', 'answer']);
$table->unsignedBigInteger('item_id');
$table->timestamps();
$table->unique(['user_id', 'item_type', 'item_id']);
$connection = Schema::getConnection()->getDriverName();
if ($connection === 'mysql') {
$table->foreign('item_id')
->references('id')
->on('questions')
->onUpdate('cascade')
->onDelete('cascade');
$table->whereRaw('(item_type = "answer" AND EXISTS (SELECT * FROM answers WHERE id = favorites.item_id))');
} else {
$table->morphTo('item');
}
});
}
/**
* Reverse the migrations.
*/
public function down()
{
Schema::dropIfExists('favorites');
}
}
答: 暂无答案
评论
where
ON DELETE
蓝图
类,但您尝试使用的方法属于Builder
和Model
类......$table->whereRaw(...)
$table->morphTo('item')
$table
where
where