php项目运行php artisan migrate报错

问题遇到的现象和发生背景

运行php artisan migrate进行建表操作

问题相关代码,请勿粘贴截图
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateProjectWorkOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('project_work_orders', function (Blueprint $table){

            $table->increments('id');
            $table->integer('job_id');
            $table->integer('project_id');
            $table->string('device_area')->nullable()->comment('设备区域');
            $table->string('work_approver')->nullable()->comment('工作许可人');
            $table->integer('order')->default(0)->comment('许可顺序');
            $table->text('remark')->nullable()->comment('备注');

            $state = \App\SelectOption::where('name', '编写')
                ->where('optionable_type',\App\ProjectWorkOrder::class)
                ->first()->id;
            $table->integer('state')->default($state)->commment('状态');
            $table->timestamps();
        });
    }

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


运行结果及报错内容

img

img

我的解答思路和尝试过的方法

初次使用php,网上没有找到相关案例

我想要达到的结果

不知道如何解决现在这个问题,希望各位帮帮忙,指点指点!

$table代表的意思我懂,但是不知道$state这一小段代码具体代表什么含义。

确定$state的first()获取到数据了?

原因:
查询语句的where条件,字段值怎么会等于一个类对象呢,肯定查不到数据,所以没有id属性报错

解决:
第一,更改对的where条件;
第二,做个判断,有查询结果才使用;

$state = (int)\App\SelectOption::where('name', '编写')
                ->where('optionable_type', ‘project_work_order’) // 自行修改为对的条件
                ->value(‘id’);

$table->integer('state')->default($state ?? 1)->commment('状态');