mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
改进Route类
This commit is contained in:
@@ -1336,22 +1336,31 @@ class Route
|
|||||||
$bind = [];
|
$bind = [];
|
||||||
foreach ($option['bind_model'] as $key => $val) {
|
foreach ($option['bind_model'] as $key => $val) {
|
||||||
if ($val instanceof \Closure) {
|
if ($val instanceof \Closure) {
|
||||||
$bind[$key] = call_user_func_array($val, [$matches]);
|
$result = call_user_func_array($val, [$matches]);
|
||||||
} else {
|
} else {
|
||||||
if (is_array($val)) {
|
if (is_array($val)) {
|
||||||
parse_str($val[1], $fields);
|
$fields = explode('&', $val[1]);
|
||||||
$model = $val[0];
|
$model = $val[0];
|
||||||
} else {
|
} else {
|
||||||
$fields = ['id'];
|
$fields = ['id'];
|
||||||
$model = $val;
|
$model = $val;
|
||||||
}
|
}
|
||||||
$where = [];
|
$where = [];
|
||||||
|
$match = true;
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
if (isset($matches[$field])) {
|
if (!isset($matches[$field])) {
|
||||||
|
$match = false;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
$where[$field] = $matches[$field];
|
$where[$field] = $matches[$field];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$bind[$key] = $model::where($where)->find();
|
if ($match) {
|
||||||
|
$result = $model::where($where)->findOrFail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!empty($result)) {
|
||||||
|
$bind[$key] = $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$matches = array_merge($matches, $bind);
|
$matches = array_merge($matches, $bind);
|
||||||
|
|||||||
Reference in New Issue
Block a user