运行composer update后查询异常

时间:2016-10-19 06:24:23

标签: php mysql laravel-5

我想添加导入/导出功能所以,我做了作曲家更新以安装maatwebsite但突然我得到了这个

  

Connection.php第651行中的QueryException:SQLSTATE [42S22]:列不是   发现:1054未知列'accessdetail.targetUserId'在'where   子句'(SQL:从accessheader选择filePathaccessheader   accessdetail上的内部联接accessheaderid =   accessdetailaccessId其中accessdetailtargetUserId = 2)

我试过“composer require”,它仍然给出相同的结果。在运行作曲家更新之前,它进展顺利。所以,我好奇为什么。

FileController.php

public function index(Request $request)
    {
        $folder = $request::get('folder');

        //return Storage::disk('local')->directories("/");

        $data = $this->manager->folderInfo($folder);

        $login = auth()->user();

        /*
         * Base Folder?
         * */

        $ownedFolder = '';

        if (!is_null($login->staffId)) {
            $ownedFolder = AccessHeader::where('name',$login->staffs['position'])->first();
        } elseif (!is_null($login->pengurusId)) {
            $ownedFolder = AccessHeader::where('name',$login->pengurus['department'])->first();
        }

        $baseFolder = $ownedFolder['filePath'];                              // /Media/

        $baseFolder = substr($baseFolder, 0, strlen($baseFolder) - 1);          // /Media
        $ownedFolder = Str::is($baseFolder,$folder);
        $baseFolder = Str::is($baseFolder . '*',$folder);                    // 1

        /*if($folder == $baseFolder){
            $baseFolder = 1;
        }else if($folder != $baseFolder){
            $baseFolder = 0;
        };*/


        /*
         * Others Folder?
         * */
        //return $data['folder'];

        $nowFolder = AccessHeader::where('filePath','like',$data['folder'].'%')->first();

        $sharedFolder = AccessDetail::where('accessId',$nowFolder['id'])->get();

        $baseSharedFolder = $othersFolder = $othersBaseFolder = '';

        if($sharedFolder->isEmpty()){
            $sharedFolder = AccessDetail::where('accessId',$nowFolder['parentAccessId'])->get();
            if(!$sharedFolder->isEmpty()){
                if($nowFolder['userId'] == $login->id && $nowFolder['parentAccessId'] == null) {
                    $othersFolder = 0;
                }else {
                    $othersFolder = 1;
                }
            }else{

                $othersFolder = 0;
                if($nowFolder['parentAccessId'] != null) {
                    $baseSharedFolder = 0;
                }else{
                    $baseSharedFolder = 1;
                }
            }
        }

        /**
         * Klo tidak empty
        */

        else{
            if($nowFolder['userId'] == $login->id && $nowFolder['parentAccessId'] == null){ //folderkita
                $othersFolder = 0;
                $baseSharedFolder = 1;
/*                if($othersFolder['accessParentId'] == null){
                    $baseSharedFolder = 1;
                }else{
                    $baseSharedFolder = 0;
                }*/
            }else{
                $othersFolder = 1;
            }
        }

        $accessh = '';

        $flag[0] = 2;
        $flag[1] = 2;
        $loginArray = '';

        if (!is_null($login->staffId)) {
            $loginArray[] = $login->staffs->position;
        }elseif(!is_null($login->pengurusId)){
            $loginArray[] = $login->pengurus->department;
        }

        //foreach ($data['subfolders'] as $path) {
            //$accessh = AccessHeader::where('filePath', $path . '/')->first()['userId'];
            $aheadsFolder = AccessHeader::select('filePath')
                ->where('userId', $login->id)
                ->where('type', 'folder')
                ->whereNotIn('name',$loginArray)
                ->get();

            $aheadsFile = AccessHeader::select('filePath')
                ->where('userId', $login->id)
                ->where('type', 'file')
                ->get();

        $shareTo = AccessHeader::where('filePath',$folder.'/');

        $sharedToSekretarisJenderal = $sharedToWakilSekretarisJenderal = $sharedToSekretaris = $sharedToFundraiser
        = $sharedToKeuangan = $sharedToLiteratur = $sharedToMedia = $sharedToUmum
        = $sharedToPengurusHarianNasional = $sharedToBadanPengurusNasional
            = $sharedToBadanPembina = $sharedToBadanPengawas =  0;

        if(!$shareTo->get()->isEmpty()) {
            if (!$shareTo->first()->accessDetails->where('shareTo','Badan Pembina')->isEmpty()){
                $sharedToBadanPembina = 1;
            };

            if (!$shareTo->first()->accessDetails->where('shareTo','Badan Pengawas')->isEmpty()){
                $sharedToBadanPengawas = 1;
            };

            if (!$shareTo->first()->accessDetails->where('shareTo','Pengurus Harian Nasional')->isEmpty()){
                $sharedToPengurusHarianNasional = 1;
            };

            if (!$shareTo->first()->accessDetails->where('shareTo','Badan Pengurus Nasional')->isEmpty()){
                $sharedToBadanPengurusNasional = 1;
            };

            if (!$shareTo->first()->accessDetails->where('shareTo','Wakil Sekretaris Jenderal')->isEmpty()){
                $sharedToWakilSekretarisJenderal = 1;
            }

            ;if (!$shareTo->first()->accessDetails->where('shareTo','Sekretaris Jenderal')->isEmpty()){
                $sharedToSekretarisJenderal = 1;
            };

            if (!$shareTo->first()->accessDetails->where('shareTo','Sekretaris')->isEmpty()){
                $sharedToSekretaris = 1;
            }

            if (!$shareTo->first()->accessDetails->where('shareTo','Keuangan')->isEmpty()){
                $sharedToKeuangan = 1;
            }

            if (!$shareTo->first()->accessDetails->where('shareTo','Fundraiser')->isEmpty()){
                $sharedToFundraiser = 1;
            }

            if (!$shareTo->first()->accessDetails->where('shareTo','Media')->isEmpty()){
                $sharedToMedia = 1;
            }

            if (!$shareTo->first()->accessDetails->where('shareTo','Umum')->isEmpty()){
                $sharedToUmum = 1;
            }

            if (!$shareTo->first()->accessDetails->where('shareTo','Literatur')->isEmpty()){
                $sharedToLiteratur = 1;
            }
        }

        return view('file.file_lists',$data,compact(
            'sharedToBadanPembina',
            'sharedToBadanPengawas',
            'sharedToPengurusHarianNasional',
            'sharedToBadanPengurusNasional',
            'sharedToSekretarisJenderal',
            'sharedToWakilSekretarisJenderal',
            'sharedToSekretaris',
            'sharedToKeuangan',
            'sharedToFundraiser',
            'sharedToUmum',
            'sharedToLiteratur',
            'sharedToMedia',
            'myFolder','login','aheadsFolder','aheadsFile','baseFolder','accessh','flag','othersFolder','baseSharedFolder'));
    }

create_access_header_table.php

  public function up()
        {
            Schema::create('accessHeader', function (Blueprint $table) {
                $table->increments('id');
                $table->integer('accessTypeId')->unsigned();
                $table->string('name');
                $table->unsignedInteger('parentAccessId')->nullable();
                $table->longText('filePath');
                $table->integer('userId')->unsigned();
                $table->string('type');
                $table->timestamps();

                $table->foreign('userId')->references('id')->on('logins');
                $table->foreign('accessTypeId')->references('id')->on('accesstypes');

            });
        }

create_access_detail_table.php

public function up()
    {
        Schema::create('accessDetail', function (Blueprint $table) {
            $table->increments('id');
            //$table->integer('targetUserId')->unsigned();
            $table->string('shareTo');
            $table->integer('accessId')->unsigned();
            $table->timestamps();

            //$table->foreign('targetUserId')->references('id')->on('logins')->onDelete('cascade');
            $table->foreign('accessId')->references('id')->on('accessheader')->onDelete('cascade');
        });
    }

accessheader.php

namespace App;

use Illuminate\Database\Eloquent\Model;

class AccessHeader extends Model
{
    protected $table = 'accessheader';

    protected $fillable = [
        'accessTypeId',
        'name',
        'ParentAccessId',
        'filePath',
        'userId',
        'type',
    ];

    public function accessTypes() {
        return $this->belongsTo('App\AccessType', 'accessTypeId');
    }
    public function accessDetails() {
        return $this->hasMany('App\AccessDetail', 'accessId');
    }

    public function logins(){
        return $this->belongsTo('App\Login','userId');
    }
}

accessdetail.php

namespace App;

use Illuminate\Database\Eloquent\Model;

class AccessDetail extends Model
{
    protected $table = 'accessdetail';

    protected $fillable = [
        'accessId',
    ];

    public function accessHeaders() {
        return $this->belongsTo('App\AccessHeader', 'accessId');
    }
}

1 个答案:

答案 0 :(得分:0)

这是一个查询错误,与composer无关。

错误在于您在数据库表中没有此栏目,但是,它仍在尝试在某个地方使用:

where accessdetail.targetUserId = 2

在您的迁移文件中,您已注释掉了:

$table->integer('targetUserId')->unsigned();

因此,如果您重新启动数据库,它就不会再存在了。

如果这是正确的,那么您仍然可以在查询中包含此where子句。

希望这有帮助!