Laravel哪里有错误

时间:2016-01-19 03:09:29

标签: php laravel-5.1

这是我第一次在whereHas中使用Laravel。我用它来搜索我的桌子。这是我用于搜索的查询。

$term = $request->query;

$category = Category::whereHas("contacts", function($query) use($term){
    $query->where("name", "like", "%".$term."%");
})->orWhere('name','LIKE','%'.$term.'%')->orderBy("id", 'desc')->get();

但它返回错误

Object of class Symfony\Component\HttpFoundation\ParameterBag could not be converted to string

这是我的Category型号

<?php 


namespace App;

use Illuminate\Database\Eloquent\Model;

/**
* 
*/
class Category extends Model{

    protected $fillable = ['name'];

    public function contacts(){
        return $this->hasMany("App\Contact");
    }

}

这是我的Contact型号

class Contact extends Model
{
    use SoftDeletes;

    /**
     * The attributes that should be mutated to dates.
     *
     * @var array
     */
    protected $dates = ['deleted_at'];

    protected $fillable = ['name', 'phone', 'added_by', 'city', 'location', 'verified', 'category_id', 'bio'];

public function category(){
        return $this->belongsTo("App\Category");
    }

}

0 个答案:

没有答案