我有一个条件查询在索引控制器中工作,该查询应该返回雄辩的关系,但并不总是返回可访问的数组索引:
from flask import Flask, request, session
from twilio.twiml.messaging_response import MessagingResponse
SECRET_KEY = 'a secret key'
app = Flask(__name__)
app.config.from_object(__name__)
@app.route("/sms", methods=['GET','POST'])
def sms_logic():
try:
# Increment the counter
counter = session.get('counter',0)
# Initiate conversation + Save the new counter value in the session
body = request.values.get('Body', None)
counter += 1
session['counter'] = counter
# start our TwiML response
resp = MessagingResponse()
if counter == 1 and body.lower() == 'target_string':
resp.message('response 1')
elif counter == 1 and body.lower() != 'target_string':
resp.message('Unknown entry. Please try again.')
session.clear()
else:
resp.message('response 2 ')
session.clear()
#print(counter)
return(str(resp))
except Exception as e:
pass
if __name__ == "__main__":
app.run(debug=True)
问题是相关数组并不总是可访问的,例如order [1],当我dd($ customers)时显示奇怪;
$customers = Customer::with('orders', 'regions')->orderBy('created_at', 'desc')->whereHas('regions', function($query)
{
$user_id = Auth::user()->id;
$current_user = User::with('roles')->where('id', '=', $user_id)->latest()->first();
$role_name = $current_user->roles[0]->name;
if($role_name == 'admin_master'){$query->whereIn('region', array(11, 7));}
}
)->get();
答案 0 :(得分:0)
对于将来的用户,get
方法将结果作为集合来获取。您可以在其上链接toArray()
方法以将其转换为数组。
因此它将类似于$query->get()->toArray()