BallOon

2627 经验值

当我执行
//
php artisan queue:work
//
之后
//
[2017-09-08 09:56:41] Processing: AppJobsWechatJpush
[2017-09-08 09:56:42] Processing: AppJobsWechatJpush
[2017-09-08 09:56:42] Processing: AppJobsWechatJpush
[2017-09-08 09:56:42] Processing: AppJobsWechatJpush
[2017-09-08 09:56:43] Processing: AppJobsWechatJpush
[2017-09-08 09:56:44] Processing: AppJobsWechatJpush
[2017-09-08 09:56:44] Processing: AppJobsWechatJpush
[2017-09-08 09:56:45] Processing: AppJobsWechatJpush
[2017-09-08 09:56:45] Processing: AppJobsWechatJpush
[2017-09-08 09:56:46] Processing: AppJobsWechatJpush
[2017-09-08 09:56:46] Processing: AppJobsWechatJpush
[2017-09-08 09:56:46] Processing: AppJobsWechatJpush
[2017-09-08 09:56:47] Processing: AppJobsWechatJpush
[2017-09-08 09:56:47] Processing: AppJobsWechatJpush
[2017-09-08 09:56:51] Processing: AppJobsWechatJpush
[2017-09-08 09:56:51] Processing: AppJobsWechatJpush
[2017-09-08 09:56:52] Processing: AppJobsWechatJpush
[2017-09-08 09:56:52] Processing: AppJobsWechatJpush
[2017-09-08 09:56:53] Processing: AppJobsWechatJpush
[2017-09-08 09:56:53] Processing: AppJobsWechatJpush
//
并没有执行成功,想问下这个问题出现的大概在哪个地方,前几天都很好的运行 今天不行了。。

解决啦,是因为php artisan serve的问题,默认的env配置会缓存起来,重新重启下就OKl啦

问题就是当我去修改比如redis的一些配置项或者一些env文件里面的比如redis密码的时候,在程序中去打印出相应的配置时候,并不生效。

我看了eql的视频我发现那个是1对多的多态,而不是多对多的多态处理

{"message":"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'tags.tags_id' in 'field list' (SQL: select news.*, tags.tags_id as pivot_tags_id from news inner join tags on news.id = tags.tags_id where tags.tags_id = 1 and tags.tags_type = App\\Api\\V1\\Models\\News)","code":"42S22","status_code":500}

然后如果我在tags表里面加入,tags_id 和tags_type 那么打印的SQL

array:2 [
  0 => array:3 [
    "query" => "select * from `tags` where `tags`.`id` = ? limit 1"
    "bindings" => array:1 [
      0 => 2
    ]
    "time" => 13.0
  ]
  1 => array:3 [
    "query" => "select `news`.*, `tags`.`tags_id` as `pivot_tags_id` from `news` inner join `tags` on `news`.`id` = `tags`.`tags_id` where `tags`.`tags_id` = ? and `tags`.`tags_type` = ?"
    "bindings" => array:2 [
      0 => 2
      1 => "App\Api\V1\Models\News"
    ]
    "time" => 3.0
  ]
]

但是这样的话有个问题,问题是为啥inner join的查询是

 `news`.`id` = `tags`.`tags_id`

而不是

 new.tags_id=tags.id

为啥我的反了
tags.id =news.tags_id 这样才OK吧,为啥我的事反了的

<?php
/**

  • Created by PhpStorm.

  • User: Administrator

  • Date: 2017/7/31

  • Time: 10:29
    */

namespace AppApiV1Models;

use IlluminateDatabaseEloquentModel;

class Tags extends Model
{

protected $table ='tags';
public function news()
{
    return $this->morphedByMany(News::class,'tags');
}
public function lessons()
{
    return $this->morphedByMany(Lesson::class);
}

}

这是我的Model代码

这是报错
{"message":"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'tags.tags_id' in 'field list' (SQL: select news.*, tags.tags_id as pivot_tags_id from news inner join tags on news.id = tags.tags_id where tags.tags_id = 1 and tags.tags_type = App\Api\V1\Models\News)","code":"42S22","status_code":500}

$lists =News::paginate(5);

   foreach($lists as $k =>&$v){
     $tags = explode(',',$v['tags_id']);
       $v['tags'] = Tags::whereIn('id',$tags)->get(['id','tag_name']);
   }
   return $lists;

我最后是这样得出数据的 ,但是这样的话 有没有哪里可以优化的地方呢