调整农作物父级路径

dev
vine_liutk 2023-03-23 10:59:45 +08:00
parent 37b5afa7c7
commit c33da0e803
3 changed files with 8 additions and 4 deletions

View File

@ -26,7 +26,9 @@ class CropController extends Controller
//如果有上级录入path
if ($input['parent_id'] ?? 0) {
$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);
@ -56,7 +58,9 @@ class CropController extends Controller
//如果有上级录入path
if ($input['parent_id'] ?? 0) {
$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));

View File

@ -186,7 +186,7 @@ class CropYieldController extends Controller
} else {
$cropQ = Crop::query();
if ($crop) {
$cropQ->where('path', 'like', '%'.$crop->id.'-');
$cropQ->where('path', 'like', '%-'.$crop->id.'-');
} else {
$cropQ->where('category_id', $categoryId);
}

View File

@ -170,7 +170,7 @@ class CropSeeder extends Seeder
'category_id' => $item['category_id'],
'crop_type' => $item['crop_type'],
'parent_id' => $parentCrop ? ($parentCrop?->id ?? 0) :0,
'path' => $parentCrop ? (($parentCrop?->path ?? '').$parentCrop->id.'-'):'',
'path' => $parentCrop ? (($parentCrop?->path ?? '-').$parentCrop->id.'-'):'-',
'unit' => $item['unit'],
'extends' => isset($item['extends']) ? json_encode($item['extends']) : null,
'is_end' => isset($item['children']) ? 0 : 1,