# Department

resources / views / Department /

# Index.Blade

resources / views / Department / index.blade.php

@extends('layouts.master')
@section('page-title') Department @endsection
@section('content')
    <div class="mb-2">
        <nav aria-label="breadcrumb" class="bg-white p-2 shadow-sm rounded">
            <ol class="breadcrumb mb-0">
                <li class="breadcrumb-item active" aria-current="page">Department /</li>
            </ol>
        </nav>
    </div>
    <div class="card border-0 shadow-sm rounded">
        <div class="card-body">
            <div class="d-flex justify-content-between align-items-center">
                <h4 class="fw-bold text-black-50 mb-0">
                    <i class="fa-solid fa-layer-group me-1"></i>Department Lists
                </h4>
                @can('Create Department')
                <a href="{{ route('department.create') }}" class="btn btn-outline-primary">
                    <i class="fa-solid fa-square-plus"></i>
                </a>
                @endcan
            </div>
            <hr>
            <table class="table table-hover w-100" id="employee-table">
                <thead class="bg-primary text-white">
                <tr>
                    <th class="no-sort no-search">Control</th>
                    <th class="text-nowrap">Title</th>
                    <th class="no-sort no-search">Action</th>
                    <th>Date</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
@endsection
@section('js')

<script>

$(document).ready(function (){

    let table = $('#employee-table').DataTable({

        ajax: '{{ route('department.dataTable') }}',
        columns: [
            { data: 'plus_icon', name: 'plus_icon' },
            { data: 'title', name: 'title' },
            { data: 'action', name: 'action' },
            { data: 'created_at', name: 'created_at' },
        ],
        order: [[ 1, "asc"]],
        columnDefs: [
            {
                "targets": [ 0 ],
                "class": "control"
            },
            {
                "targets": [3],
                "visible": false
            },
            {
                "targets": 'no-sort',
                "orderable": false
            },
            {
                "targets": 'no-search',
                "searchable": false
            },
            {
                "targets": 'hidden',
                "visible": false
            }
        ],
    });

    $(document).on('click','.delete-btn', function (e){
        e.preventDefault();
        let id = $(this).data('id');
        let name = $(this).data('name');
        Swal.fire({
            title: 'Are you sure?',
            text: "You won't be able to revert this!",
            icon: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#f15858',
            confirmButtonText: 'Delete'
        }).then((result) => {
            if (result.isConfirmed) {
                $.ajax({
                    method: "DELETE",
                    url: `/department/${id}`,
                }).done(function (res){
                    Swal.fire(
                        'Deleted!',
                        "<span class='fw-bold text-black'>"+ name +"</span>" + " has been deleted.",
                        'success'
                    );
                    table.ajax.reload();
                });
            }
        })
    });
});
</script>
@endsection
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

# Demo

departmentLists

# Create.Blade

resources / views / Department / create.blade.php

@extends('layouts.master')
@section('page-title') Department @endsection
@section('content')
    <div class="mb-2">
        <nav aria-label="breadcrumb" class="bg-white p-2 shadow-sm rounded">
            <ol class="breadcrumb mb-0">
                <li class="breadcrumb-item">
                    <a href="{{ route('department.index') }}" class="text-decoration-none">Department</a>
                </li>
                <li class="breadcrumb-item active" aria-current="page">Create New Department</li>
            </ol>
        </nav>
    </div>
    <div class="card border-0 shadow-sm rounded">
        <div class="card-body">
            <div class="d-flex justify-content-between align-items-center">
                <h4 class="fw-bold text-black-50 mb-0">
                    <i class="fa-solid fa-square-plus me-1"></i>Create New Department
                </h4>
                <a href="{{ route('department.index') }}" class="btn btn-outline-primary">
                    <i class="fa-solid fa-list"></i>
                </a>
            </div>
            <hr>
            <form action="{{ route('department.store') }}"
                  method="post" id="create-department"
                  class="row justify-content-center py-2">
                @csrf
                <div class="col-12 col-md-8">
                    <div class="form-floating mb-3">
                        <input type="text" class="form-control"
                               id="title" name="title" placeholder="title">
                        <label for="title">Department's Title</label>
                    </div>
                </div>
                <div class="col-12 col-md-6 my-3">
                    <button class="btn btn-primary w-100">Save Department</button>
                </div>
            </form>
        </div>
    </div>
@endsection
@section('js')
    {!! JsValidator::formRequest('App\Http\Requests\StoreDepartmentRequest','#create-department') !!}
@endsection
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

StoreDepartmentRequest

# Edit.Blade

resources / views / Department / edit.blade.php

@extends('layouts.master')
@section('page-title') Department @endsection
@section('content')
    <div class="mb-2">
        <nav aria-label="breadcrumb" class="bg-white p-2 shadow-sm rounded">
            <ol class="breadcrumb mb-0">
                <li class="breadcrumb-item">
                    <a href="{{ route('department.index') }}" class="text-decoration-none">Department</a>
                </li>
                <li class="breadcrumb-item active" aria-current="page">Update Department</li>
            </ol>
        </nav>
    </div>
    <div class="card border-0 shadow-sm rounded">
        <div class="card-body">
            <div class="d-flex justify-content-between align-items-center">
                <h4 class="fw-bold text-black-50 mb-0">
                    <i class="fa-solid fa-square-plus me-1"></i>Update Department
                </h4>
                <a href="{{ route('department.index') }}" class="btn btn-outline-primary">
                    <i class="fa-solid fa-list"></i>
                </a>
            </div>
            <hr>
            <form action="{{ route('department.update', $department->id) }}"
                  method="post" id="create-department"
                  class="row justify-content-center py-2">
                @csrf
                @method('put')
                <div class="col-12 col-md-8">
                    <div class="form-floating mb-3">
                        <input type="text" class="form-control"
                               id="title" name="title" value="{{$department->title}}"
                               placeholder="title">
                        <label for="title">Department's Title</label>
                    </div>
                </div>
                <div class="col-12 col-md-6 my-3">
                    <button class="btn btn-primary w-100">Update Department</button>
                </div>
            </form>
        </div>
    </div>
@endsection
@section('js')
    {!! JsValidator::formRequest('App\Http\Requests\UpdateDepartmentRequest','#create-department') !!}
@endsection
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

UpdateDepartmentRequest

Last Updated: 6/2/2022, 9:53:32 PM