2017-12-20 15 views
0

エラーが移行した後起こった:ここで私は分かりませんが、多分それはユニークな検証によってユニークスロー[42S22]:カラム見つかりません:1054不明列

を引き起こす

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: select count(*) as aggregate from `phone` where `phone_number` = 0883991010 and `id` <>) 

をリフレッシュすることは私ですコントローラ

if ($this->method() == 'PATCH') { 
     $name_rules = 'required|string|size:4|unique:student,name,' . $this->get('id'); 
     $phone_rules = 'sometimes|numeric|digits_between:10,15|unique:phone,phone_number,' . $this->get('id') . ',id_student'; 
    } 

    else { 
     $name_rules = 'required|string|size:4|unique:student,name,'; 
     $phone_rules = 'sometimes|numeric|digits_between:10,15|unique:phone,phone_number,'; 
    } 

Phone.php

依頼
<?php 

namespace App; 

use Illuminate\Database\Eloquent\Model; 

class Phone extends Model 
{ 
    // 
    protected $table = 'phone'; 

    protected $primaryKey = 'id_student'; 

    protected $fillable = [ 

     'id_student', 
     'phone_number', 
    ]; 



    public function student() 
    { 
     return $this->belongsTo('App\Student', 'id_student'); 
    } 
} 

スキーマ

public function up() 
{ 

    Schema::create('phone', function (Blueprint $table) 
    { 

     $table->integer('id_student')->unsigned()->primary('id_student'); 
     $table->string('phone_number')->unique(); 
     $table->timestamps(); 

     $table->foreign('id_student')->references('id')->on('tudent')->onDelete('cascade')->onUpdate('cascade'); 
    }); 

} 

それは私がユニーク取り除く際に正常に動作します:電話、PHONE_NUMBER、

任意のより良い提案?

+0

を試してみていただきました!あなたは電話番号を格納するテーブルの名前は? –

+0

テーブルのphone_number属性の列を確認します。 –

+0

しかし、これらのコード行にはデータベースのアクティビティはありません。 – Amarnasan

答えて

0

各検証チェックでカスタムプライマリキーを指定する必要がありますが、それらのキーでのみ実行しています。

この

if ($this->method() == 'PATCH') { 
     $name_rules = 'required|string|size:4|unique:student,name,' . $this->get('id'). ',id_student'; 
     $phone_rules = 'sometimes|numeric|digits_between:10,15|unique:phone,phone_number,' . $this->get('id') . ',id_student'; 
    } 

    else { 
     $name_rules = 'required|string|size:4|unique:student,name,' . $this->get('id'). ',id_student'; 
     $phone_rules = 'sometimes|numeric|digits_between:10,15|unique:phone,phone_number,' . $this->get('id') . ',id_student'; 
    } 
+0

多くのおかげで携帯電話のルールと同じ列に名前を持っています私は試して結果にあなたに戻ってきます –

+0

@ YudyAnandaは、この答えは正しいですか?。はいの場合は、答えを正しいとマークすることができます! –

+0

それは何も変更しません、それはまだ同じエラーです。今私は要求を使用していないので、私はエラーの検証をコントローラに戻します(ストア&更新)あなたは手がかりを持っていますか? –

関連する問題