我在laravel 4中查询数据库,但无法在此处访问返回的值是代码:
public class Customer
{
private String city;
private String address;
private String cel;
private String email;
private String name;
private int customerID;
public enum camposCust{
city,
address,
cel,
email,
name,
_customerID
}
public void setCity(String city)
{
this.city = city;
}
public String getCity()
{
return city;
}
public void setAddress(String address)
{
this.address = address;
}
public String getAddress()
{
return address;
}
public void setCel(String cel)
{
this.cel = cel;
}
public String getCel()
{
return cel;
}
public void setEmail(String email)
{
this.email = email;
}
public String getEmail()
{
return email;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setCustomerID(int customerID)
{
this.customerID = customerID;
}
public int getCustomerID()
{
return customerID;
}
}
所以该函数返回此public static function getCityIdByName($cityname){
$cityid = DB::select( DB::raw(" SELECT id FROM cities WHERE match(city_name) against('*" .
$cityname . "*' IN BOOLEAN MODE ) " ));
return $cityid;
}
并且我需要获得价值" 1",我尝试了[{"id":1}]
和$cityid->id
以及$cityid['id']
但这一切都是返回错误,也不是字符串,当我回显它时,它抱怨数组不是字符串$cityid[0]
答案 0 :(得分:0)
我用这段代码解决了这个问题:
git push -u origin master
感谢@ Sylwit
答案 1 :(得分:0)
即使它有效,你也可以改进它
如果你有几个结果,你只需要第一个数组就可以得到所有结果。
您还可以在查询中使用->first()
来获取第一个避免使用[0]的对象。
一个有趣的链接 https://laracasts.com/discuss/channels/eloquent/is-this-match-against-using-relevance-possible