Mysql 迁移中的条件语句不';t工作拉威尔

Mysql 迁移中的条件语句不';t工作拉威尔,mysql,conditional,database-schema,laravel-5.1,Mysql,Conditional,Database Schema,Laravel 5.1,我有个小问题。我有一个表,其中field owntype的值为0,field owner属性为表玩家的ID,如果field owntype的值为1,则应将所有者的值指定为0,如果field owntype为2,则从表vehicles中指定所有者ID,我知道如何使其工作?下面我包括了一些表,调用模型可以毫无问题地工作,因为我可以完成所有支持的迁移表 带条件语句的事物表: <?php use Illuminate\Database\Schema\Blueprint; use Illumina

我有个小问题。我有一个表,其中field owntype的值为0,field owner属性为表玩家的ID,如果field owntype的值为1,则应将所有者的值指定为0,如果field owntype为2,则从表vehicles中指定所有者ID,我知道如何使其工作?下面我包括了一些表,调用模型可以毫无问题地工作,因为我可以完成所有支持的迁移表

带条件语句的事物表:

<?php

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

class CreateThingsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('things', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('object')->default(0);
            $table->tinyInteger('category')->default(0);
            $table->string('name');
            $table->integer('owner')->unsigned()->nullable();
            $table->integer('owntype')->default(0);
            $table->integer('number')->default(0);
            $table->integer('value1')->default(0);
            $table->integer('value2')->default(0);
            $table->integer('damage')->default(1);
            $table->float('pos_x');
            $table->float('pos_y');
            $table->float('pos_z');
            $table->tinyInteger('pos_vw');
            $table->integer('use')->default(0);
            $table->timestamp('date');
            $table->timestamps();

            if(Schema::hasColumn('things', 'owntype') == 0) 
            {
                $table->foreign('owner')->references('id')->on('players')->onDelete('cascade');
            }
            elseif(Schema::hasColumn('things', 'owntype') == 1)
            {
                Schema::table('things', function ($table) {
                    return $table->integer('owner')->unsigned()->nullable()->change();
                });
            }
            elseif(Schema::hasColumn('things', 'owntype') == 2)
            {
                $table->foreign('owner')->references('id')->on('vehicles')->onDelete('cascade');
            }

        });




    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('things');
    }
}
我这样做了:

public function queryThing($query) 
{ 
  return $query->where('owntype', 0); 
} 

喂,有人能帮忙吗?这很重要。
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Player extends Model
{
    protected $table = 'players';

    protected $fillable = 
    [
        'name',
        'age',
        'gid',
        'sex',
        'skin',
        'from',
        'history',
        'online'
    ];

    public function user()
    {
        return $this->belongsTo('App\User');
    }

    public function formatName($name)
    {
        $nick = str_replace("_", " ", $name);
        return $nick;
    }

    public function checkActive($active)
    {
        if($active == 0)
        {
            $showActive = '<span class="label label-error">Zablokowana</span>';
            return $showActive;
        }


        if($active == -999)
        {
            $showActive = '<span class="label label-default"><s>Zbanowana</s></span>';
            return $showActive;
        }


        if($active == 1)
        {
            $showActive = '<span class="label label-success">Aktywna</span>';
            return $showActive;
        }

    }

    public function formatTime($time)
    {
        $hours = floor($time / 60);
        $minutes = $time - ($hours * 60);
        return $hours.'h '.$minutes.'min.';
    }

    public function formatSex($sex)
    {
        if($sex == 0)
        {
            $man = 'Mężczyzna';
            return $man;
        }
        else
        {
            $girl = 'Kobieta';
            return $girl;
        }
    }

    public function formatKP($kp)
    {
        if($kp == 1)
        {
            $showKP = '<span class="label label-warning">Gracz premium!</span>';
            return $showKP;
        }
    }

    public function ban()
    {
        return $this->hasOne('App\Ban', 'player_name', 'name');
    }

    public function busines()
    {
        return $this->belongsTo('App\Busines', 'bmember');
        return $this->belongsTo('App\Busines', 'bleader');
    }

    public function organization()
    {
        return $this->belongsTo('App\Organization', 'member');
        return $this->belongsTo('App\Organization', 'leader');
    }

    public function house()
    {
        return $this->hasMany('App\House', 'owner');
    }

    public function thing()
    {
        return $this->hasMany('App\Thing', 'owner');
    }

    public function login()
    {
        return $this->hasMany('App\Login', 'nickname', 'name');
    }
}
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Vehicle extends Model
{
    protected $table = 'vehicles';

    public function thing()
    {
        return $this->hasMany('App\Thing', 'owner');
    }
}
public function queryThing($query) 
{ 
  return $query->where('owntype', 0); 
}