/
home
/
sjslayjy
/
public_html
/
ccbfsoution
/
Upload File
HOME
@extends('layouts.app') @section('title', 'Land Management') @section('content') <style> .btn-add { background-color: #6b8e23; color: white; padding: 8px 12px; border-radius: 6px; font-size: 14px; border: none; } .modal-content { border-radius: 12px; padding: 20px; } .form-control { border-radius: 8px; padding: 10px; } .d-flex { display: flex; align-items: center; } .input-group { width: 250px; } </style> <div class="container-fluid"> <div class="card-body"> {{-- Validation and Session Messages --}} @if(session('success')) <div class="alert alert-success alert-dismissible fade show" role="alert"> {{ session('success') }} <button type="button" class="btn-close" data-bs-dismiss="alert"></button> </div> @endif @if(session('error')) <div class="alert alert-danger alert-dismissible fade show" role="alert"> {{ session('error') }} <button type="button" class="btn-close" data-bs-dismiss="alert"></button> </div> @endif {{-- Filter and Search Section --}} <div class="row mb-3"> <div class="col-md-12"> <div class="d-flex justify-content-between"> <div class="d-flex"> {{-- Block Filter --}} <form method="GET" action="{{ route('lands.index') }}" class="me-1"> <div class="input-group"> <select name="block" class="btn-add" onchange="this.form.submit()"> <option value="">All Blocks</option> @foreach($blocks as $block) <option value="{{ $block }}" {{ $selectedBlock == $block ? 'selected' : '' }}> {{ $block }} </option> @endforeach </select> </div> </form> {{-- Add Land Button --}} <button class="btn btn-add ms-1" data-bs-toggle="modal" data-bs-target="#landModal"> <i class="fas fa-plus"></i> Add Land </button> </div> {{-- Search Input --}} <form method="GET" action="{{ route('lands.index') }}" class="ms-auto"> <div class="input-group shadow-sm rounded-pill position-relative"> <input type="text" name="search" class="form-control border-0 ps-3" placeholder="Search..." value="{{ $search ?? '' }}" autocomplete="off"> <span class="position-absolute end-0 top-50 translate-middle-y pe-3"> <button type="submit" class="btn btn-sm p-0"> <i class="fas fa-search text-secondary"></i> </button> </span> </div> </form> </div> </div> </div> {{-- Lands Table --}} <div class="table-responsive"> <table class="table table-bordered table-striped"> <thead> <tr> <th>Sr. No.</th> <th>Plot No.</th> <th>Block</th> <th>Supervisor</th> <th>Area (Ha)</th> <th>Soil Type</th> <th>Previous Crop</th> <th>Current Crop</th> <th>Actions</th> </tr> </thead> <tbody> @forelse($lands as $index => $land) <tr> <td>{{ $lands->firstItem() + $index }}</td> <td>{{ $land->plot_no }}</td> <td>{{ $land->block }}</td> <td>{{ $land->super_wiser_name }}</td> <td>{{ $land->area_ha }}</td> <td>{{ $land->soil_type }}</td> <td>{{ $land->previous_crop }}</td> <td>{{ $land->current_crop }}</td> <td> <button class="btn btn-sm btn-warning edit-land" data-id="{{ $land->id }}" data-plot="{{ $land->plot_no }}" data-block="{{ $land->block }}" data-supervisor="{{ $land->super_wiser_name }}" data-area="{{ $land->area_ha }}" data-soil="{{ $land->soil_type }}" data-previous="{{ $land->previous_crop }}" data-current="{{ $land->current_crop }}" data-bs-toggle="modal" data-bs-target="#landModal"> Edit </button> <form action="{{ route('lands.destroy', $land->id) }}" method="POST" class="d-inline" onsubmit="return confirm('Are you sure?');"> @csrf @method('DELETE') <button type="submit" class="btn btn-sm btn-danger"> Delete </button> </form> </td> </tr> @empty <tr> <td colspan="9" class="text-center">No land records found.</td> </tr> @endforelse </tbody> </table> {{ $lands->appends(request()->input())->links() }} </div> </div> </div> {{-- Land Modal --}} <div class="modal fade" id="landModal" tabindex="-1"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">Land Details</h5> <button type="button" class="btn-close" data-bs-dismiss="modal"></button> </div> <div class="modal-body"> <form id="landForm" method="POST"> @csrf <input type="hidden" name="_method" id="formMethod" value="POST"> <input type="hidden" name="id" id="landId"> <div class="row"> <div class="col-md-6 mb-3"> <label>Plot No.</label> <input type="text" name="plot_no" class="form-control" required> </div> <div class="col-md-6 mb-3"> <label>Block</label> <select name="block" class="form-select" required> @foreach($blocks as $block) <option value="{{ $block }}">{{ $block }}</option> @endforeach </select> </div> <div class="col-md-6 mb-3"> <label>Supervisor Name</label> <input type="text" name="super_wiser_name" class="form-control" required> </div> <div class="col-md-6 mb-3"> <label>Area (Ha)</label> <input type="number" step="0.01" name="area_ha" class="form-control" required> </div> <div class="col-md-6 mb-3"> <label>Soil Type</label> <select name="soil_type" class="form-select" required> @foreach($soilTypes as $soil) <option value="{{ $soil }}">{{ $soil }}</option> @endforeach </select> </div> <div class="col-md-6 mb-3"> <label>Previous Crop</label> <input type="text" name="previous_crop" class="form-control"> </div> <div class="col-md-12 mb-3"> <label>Current Crop</label> <input type="text" name="current_crop" class="form-control"> </div> </div> <button type="submit" class="btn btn-primary w-100">Submit</button> </form> </div> </div> </div> </div> </div> @endsection @push('scripts') <script> document.addEventListener('DOMContentLoaded', function() { const modal = document.getElementById('landModal'); const form = document.getElementById('landForm'); const formMethod = document.getElementById('formMethod'); const landId = document.getElementById('landId'); // Add Land document.querySelector('[data-bs-target="#landModal"]').addEventListener('click', function() { form.action = "{{ route('lands.store') }}"; formMethod.value = 'POST'; form.reset(); }); // Edit Land document.querySelectorAll('.edit-land').forEach(button => { button.addEventListener('click', function() { // Populate form with existing data document.querySelector('[name="plot_no"]').value = this.dataset.plot; document.querySelector('[name="block"]').value = this.dataset.block; document.querySelector('[name="super_wiser_name"]').value = this.dataset.supervisor; document.querySelector('[name="area_ha"]').value = this.dataset.area; document.querySelector('[name="soil_type"]').value = this.dataset.soil; document.querySelector('[name="previous_crop"]').value = this.dataset.previous; document.querySelector('[name="current_crop"]').value = this.dataset.current; // Set form for update form.action = `/lands/${this.dataset.id}`; formMethod.value = 'PUT'; landId.value = this.dataset.id; }); }); }); </script> @endpush