@extends('backend.layouts.app') @section('title', 'Import Departments') @section('content') @php $pageTitle = 'Import Departments'; $indexRoute = 'content-directory-department.index'; $indexLabel = 'Departments'; @endphp @include('backend.layouts.partials._page_header')

Import Departments from Excel / CSV

Upload a file to preview and validate rows before inserting or updating departments.

@if ($errors->any())
{{ $errors->first() }}
@endif

How this import works

1. Download

Use the Excel or CSV template so the headers match exactly.

2. Fill rows

One department per row. Use a unique code and both BM/EN names.

3. Preview

The system validates every row and shows what will be inserted or updated.

4. Confirm

Only valid files can be imported. All rows are saved in one database transaction.

Insert or update: if a row's code already exists, that department is updated. If the code is new, a new department is inserted.

All-or-nothing: if one row is invalid, nothing is written. Fix the file and upload it again.

1. Download template

Use the template so the column names and sample hierarchy are correct.

2. Prepare your file

  • Use .xlsx or .csv only. Convert old .xls files first.
  • code, name_bm and name_en are required.
  • Format the code column as Text in Excel if it starts with zero.
  • parent_code is optional; leave blank for a root department.
  • Use a parent code from the same file or an existing department.
  • The sample rows include three levels (TKSU (KA) → BPI → SDPI) and match the department codes used in the Staff import template (BPM, SDPI) — import departments first, then staff.
  • Maximum 5,000 rows and 200MB per file.
@csrf
@include('backend.layouts.partials._upload-hint', ['text' => 'XLSX or CSV · Max 200MB']) @error('file')

{{ $message }}

@enderror

The first worksheet is read. The first row must be the header row.

Cancel

File format

Column Required What it means Example
code Yes Unique department code. Used to match existing departments and as the target for parent_code. BPI
name_bm Yes Department name in Bahasa Malaysia. Shown in the BM interface. Bahagian Perubahan Iklim
name_en Yes Department name in English. Shown in the English interface. Climate Change Division
parent_code No Code of the parent department. Leave blank for a root department. Any existing department (or one in the same file) can be the parent — there is no depth limit. TKSU (KA)
sort No Display order within the same parent. Blank is saved as 0. 1

Existing departments are matched by code and updated. New codes are inserted. If any row is invalid, nothing will be imported.

@endsection @push('scripts') @endpush