调整农作物父级路径
parent
37b5afa7c7
commit
c33da0e803
|
|
@ -26,7 +26,9 @@ class CropController extends Controller
|
||||||
//如果有上级,录入path
|
//如果有上级,录入path
|
||||||
if ($input['parent_id'] ?? 0) {
|
if ($input['parent_id'] ?? 0) {
|
||||||
$parent = Crop::findOrFail($input['parent_id']);
|
$parent = Crop::findOrFail($input['parent_id']);
|
||||||
$input['path'] = ($parent?->path ?? '').$parent?->id.'-';
|
$input['path'] = ($parent?->path ?? '-').$parent?->id.'-';
|
||||||
|
}else{
|
||||||
|
$input['path'] = '-';
|
||||||
}
|
}
|
||||||
$crop = Crop::create($input);
|
$crop = Crop::create($input);
|
||||||
|
|
||||||
|
|
@ -56,7 +58,9 @@ class CropController extends Controller
|
||||||
//如果有上级,录入path
|
//如果有上级,录入path
|
||||||
if ($input['parent_id'] ?? 0) {
|
if ($input['parent_id'] ?? 0) {
|
||||||
$parent = Crop::findOrFail($input['parent_id']);
|
$parent = Crop::findOrFail($input['parent_id']);
|
||||||
$input['path'] = ($parent?->path ?? '').$parent?->id.'-';
|
$input['path'] = ($parent?->path ?? '-').$parent?->id.'-';
|
||||||
|
}else{
|
||||||
|
$input['path'] = '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
$crop->update(array_merge($request->input(), $input));
|
$crop->update(array_merge($request->input(), $input));
|
||||||
|
|
|
||||||
|
|
@ -186,7 +186,7 @@ class CropYieldController extends Controller
|
||||||
} else {
|
} else {
|
||||||
$cropQ = Crop::query();
|
$cropQ = Crop::query();
|
||||||
if ($crop) {
|
if ($crop) {
|
||||||
$cropQ->where('path', 'like', '%'.$crop->id.'-');
|
$cropQ->where('path', 'like', '%-'.$crop->id.'-');
|
||||||
} else {
|
} else {
|
||||||
$cropQ->where('category_id', $categoryId);
|
$cropQ->where('category_id', $categoryId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,7 @@ class CropSeeder extends Seeder
|
||||||
'category_id' => $item['category_id'],
|
'category_id' => $item['category_id'],
|
||||||
'crop_type' => $item['crop_type'],
|
'crop_type' => $item['crop_type'],
|
||||||
'parent_id' => $parentCrop ? ($parentCrop?->id ?? 0) :0,
|
'parent_id' => $parentCrop ? ($parentCrop?->id ?? 0) :0,
|
||||||
'path' => $parentCrop ? (($parentCrop?->path ?? '').$parentCrop->id.'-'):'',
|
'path' => $parentCrop ? (($parentCrop?->path ?? '-').$parentCrop->id.'-'):'-',
|
||||||
'unit' => $item['unit'],
|
'unit' => $item['unit'],
|
||||||
'extends' => isset($item['extends']) ? json_encode($item['extends']) : null,
|
'extends' => isset($item['extends']) ? json_encode($item['extends']) : null,
|
||||||
'is_end' => isset($item['children']) ? 0 : 1,
|
'is_end' => isset($item['children']) ? 0 : 1,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue