LARAVEL

Laravel & Yajra (datatables)

22.06.2021 19 dəq oxuma

Laraveldə Yajra(datatables) kitabxanasın inteqrasiya etməyi kredit sistemi üçün yazdığım məhsullar menusu üzərində izah etmək istərdim.

1.İlki öncə Mudir adlı bir qovluq yaradaq,onu içərisində isə layout qovluq və onu da içərisində layout.blade.php yaradaq

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"/>
    <meta http-equiv="X-UA-Compatible" content="ie=edge"/>
    <title>{{ config('app.name') }} - @yield('title')</title>
    <link href="{{ asset('assets/dist/css/tabler.min.css') }}" rel="stylesheet"/>
    <link href="{{ asset('assets/dist/css/tabler-flags.min.css') }}" rel="stylesheet"/>
    <link href="{{ asset('assets/dist/css/tabler-payments.min.css') }}" rel="stylesheet"/>
    <link href="{{ asset('assets/dist/css/tabler-vendors.min.css') }}" rel="stylesheet"/>
    <link href="{{ asset('assets/dist/css/demo.min.css') }}" rel="stylesheet"/>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" integrity="sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w==" crossorigin="anonymous" />
    @toastr_css
    @yield('css')
</head>
<body class="antialiased {{ \Illuminate\Support\Facades\Cookie::get('darkmode') }}">
<div class="page">
    <header class="navbar navbar-expand-md navbar-light d-print-none">
        <div class="container-xl">
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar-menu">
                <span class="navbar-toggler-icon"></span>
            </button>
            <h1 class="navbar-brand navbar-brand-autodark d-none-navbar-horizontal pe-0 pe-md-3">
                <a href="{{ route('mudir.dashboard') }}">
                    <img src="{{ asset('assets/dist/logo/logo.png') }}" width="110" height="32" alt="{{ config('app.name') }}" class="navbar-brand-image">
                </a>
            </h1>
            <div class="navbar-nav flex-row order-md-last">
                <div class="nav-item dropdown d-none d-md-flex me-3">
                    <a href="#" class="nav-link px-0" data-bs-toggle="dropdown" tabindex="-1" aria-label="Show notifications">
                        <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M10 5a2 2 0 0 1 4 0a7 7 0 0 1 4 6v3a4 4 0 0 0 2 3h-16a4 4 0 0 0 2 -3v-3a7 7 0 0 1 4 -6" /><path d="M9 17v1a3 3 0 0 0 6 0v-1" /></svg>
                        <span class="badge bg-red"></span>
                    </a>
                    <div class="dropdown-menu dropdown-menu-end dropdown-menu-card">
                        <div class="card">
                            <div class="card-body">
                                Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus ad amet consectetur exercitationem fugiat in ipsa ipsum, natus odio quidem quod repudiandae sapiente. Amet debitis et magni maxime necessitatibus ullam.
                            </div>
                        </div>
                    </div>
                </div>
                <div class="nav-item dropdown">
                    <a href="#" class="nav-link d-flex lh-1 text-reset p-0" data-bs-toggle="dropdown" aria-label="Open user menu">
                        <span class="avatar avatar-sm" style="background-image: url({{ asset('assets/dist/logo/logo.png') }})"></span>
                        <div class="d-none d-xl-block ps-2">
                            <div>{{ auth()->user()->name }}</div>
                            <div class="mt-1 small text-muted">Müdir</div>
                        </div>
                    </a>
                    <div class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
                        <a href="{{ route('profile.index') }}" class="dropdown-item">Profil & hesab</a>
                        <div class="dropdown-divider"></div>
                        <a href="{{ route('darkmode') }}" class="dropdown-item">
                            @if(\Illuminate\Support\Facades\Cookie::get('darkmode') == '')
                                Gecə rejimi
                            @else
                                Gündüz rejimi
                            @endif
                        </a>
                        <a href="{{ route('logout') }}" class="dropdown-item">Hesabdan çıx</a>
                    </div>
                </div>
            </div>
        </div>
    </header>
    <div class="navbar-expand-md">
        <div class="collapse navbar-collapse" id="navbar-menu">
            <div class="navbar navbar-light">
                <div class="container-xl">
                    <ul class="navbar-nav">
                        <li class="nav-item">
                            <a class="nav-link" href="{{ route('mudir.dashboard') }}" >
                    <span class="nav-link-icon d-md-none d-lg-inline-block"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><polyline points="5 12 3 12 12 3 21 12 19 12" /><path d="M5 12v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-7" /><path d="M9 21v-6a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v6" /></svg>
                    </span>
                    <span class="nav-link-title">
                      Əsas səhifə
                    </span>
                            </a>
                        </li>
                        <li class="nav-item active dropdown">
                            <a class="nav-link dropdown-toggle" href="#navbar-base" data-bs-toggle="dropdown" role="button" aria-expanded="false" >
                    <span class="nav-link-icon d-md-none d-lg-inline-block"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><polyline points="12 3 20 7.5 20 16.5 12 21 4 16.5 4 7.5 12 3" /><line x1="12" y1="12" x2="20" y2="7.5" /><line x1="12" y1="12" x2="12" y2="21" /><line x1="12" y1="12" x2="4" y2="7.5" /><line x1="16" y1="5.25" x2="8" y2="9.75" /></svg>
                    </span>
                                <span class="nav-link-title">
                      Ayarlar
                    </span>
                            </a>
                            <div class="dropdown-menu">
                                <div class="dropdown-menu-columns">
                                    <div class="dropdown-menu-column">
                                        <a class="dropdown-item @if(\Illuminate\Support\Facades\Route::currentRouteName() == 'magaza.index') active @endif" href="{{ route('magaza.index') }}" >
                                            Mağaza(anbar)
                                        </a>
                                        <a class="dropdown-item @if(\Illuminate\Support\Facades\Route::currentRouteName() == 'vezife.index') active @endif" href="{{ route('vezife.index') }}" >
                                            Vəzifə
                                        </a>
                                        <a class="dropdown-item @if(\Illuminate\Support\Facades\Route::currentRouteName() == 'isci.index') active @endif" href="{{ route('isci.index') }}" >
                                            İşçi
                                        </a>
                                        <a class="dropdown-item @if(\Illuminate\Support\Facades\Route::currentRouteName() == 'vahid.index') active @endif" href="{{ route('vahid.index') }}" >
                                            Vahid
                                        </a>
                                        <a class="dropdown-item @if(\Illuminate\Support\Facades\Route::currentRouteName() == 'kateqoriya.index') active @endif" href="{{ route('kateqoriya.index') }}" >
                                            Kateqoriya
                                        </a>
                                        <a class="dropdown-item @if(\Illuminate\Support\Facades\Route::currentRouteName() == 'istehsalci.index') active @endif" href="{{ route('istehsalci.index') }}" >
                                            İstehsalçı
                                        </a>
                                        <a class="dropdown-item @if(\Illuminate\Support\Facades\Route::currentRouteName() == 'marka.index') active @endif" href="{{ route('marka.index') }}" >
                                            Model
                                        </a>
                                        <a class="dropdown-item @if(\Illuminate\Support\Facades\Route::currentRouteName() == 'partnyor.index') active @endif" href="{{ route('partnyor.index') }}" >
                                            Partnyorlar
                                        </a>
                                        <a class="dropdown-item @if(\Illuminate\Support\Facades\Route::currentRouteName() == 'mehsul.index') active @endif" href="{{ route('mehsul.index') }}" >
                                            Məhsullar
                                        </a>
                                        <a class="dropdown-item @if(\Illuminate\Support\Facades\Route::currentRouteName() == 'debbe.create') active @endif" href="{{ route('debbe.create') }}" >
                                            Dəbbə
                                        </a>
                                    </div>
                                </div>
                            </div>
                        </li>

                        <li class="nav-item">
                            <a class="nav-link" href="{{ route('audit.index') }}" >
                                <i class="fa fa-history" style="padding-right: 10px;"></i>
                                <span class="nav-link-title">
                                  Audit
                                </span>
                            </a>
                        </li>
                    </ul>
                    <div class="my-2 my-md-0 flex-grow-1 flex-md-grow-0 order-first order-md-last">
                        <form action="." method="get">
                            <div class="input-icon">
                    <span class="input-icon-addon">
                      <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><circle cx="10" cy="10" r="7" /><line x1="21" y1="21" x2="15" y2="15" /></svg>
                    </span>
                                <input type="text" class="form-control" placeholder="Search…" aria-label="Search in website">
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="content">
        <div class="container-xl d-flex flex-column justify-content-center">
@yield('content')
        </div>
        <footer class="footer footer-transparent d-print-none">
            <div class="container">
                <div class="row text-center align-items-center flex-row-reverse">
                    <div class="col-lg-auto ms-lg-auto">
                        <ul class="list-inline list-inline-dots mb-0">
                            <li class="list-inline-item"><a href="./docs/index.html" class="link-secondary">Documentation</a></li>
                            <li class="list-inline-item"><a href="./license.html" class="link-secondary">License</a></li>
                            <li class="list-inline-item"><a href="https://github.com/tabler/tabler" target="_blank" class="link-secondary" rel="noopener">Source code</a></li>
                        </ul>
                    </div>
                    <div class="col-12 col-lg-auto mt-3 mt-lg-0">
                        <ul class="list-inline list-inline-dots mb-0">
                            <li class="list-inline-item">
                                Copyright &copy; 2021
                                <a href="." class="link-secondary">Tabler</a>.
                                All rights reserved.
                            </li>
                            <li class="list-inline-item">
                                <a href="./changelog.html" class="link-secondary" rel="noopener">v1.0.0-beta</a>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </footer>
    </div>
</div>
<script src="{{ asset('assets/dist/js/tabler.min.js') }}"></script>
@jquery
@toastr_js
@toastr_render
@yield('js')
</body>
</html>

2. Bu mərhəldə isə Mudir qovluğunun içərisində mehsul.blade.php yaradaq

@extends('Mudir.layout.master')

@section('title')
Məhsullar
@endsection

@section('css')
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.22/css/jquery.dataTables.min.css">
    <link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.6.5/css/buttons.dataTables.min.css">
    <link rel="stylesheet" href="https://cdn.datatables.net/select/1.3.1/css/select.dataTables.min.css">

    <style>
        table.theme-dark tr td{
            color: #656d77;
            background-color: #232e3c;
        }

        table tr td {
            width: max-content !important;
        }

        .dataTables_wrapper .dataTables_paginate .paginate_button {
            background-color: #232e3c;
            color: #FFFFFF !important;
            border: 3px solid #206bc4;
        }
        div#mehsullar_length, div#mehsullar_filter, div#mehsullar_info, span.ellipsis{
            color: #656d77 !important;
        }

        table.dataTable {
            margin: 0 0 !important;
        }
        .card {
            word-wrap: normal;
        }

        .table-mobile-md td {
            color: #656d77 !important;
        }

        #printable { display: none; }

        @media print
        {
            #non-printable { display: none; }
            #printable { display: block; }
            @page {
                margin-top: 0;
                margin-bottom: 0;
            }
            body  {
                padding-top: 1rem;
                padding-bottom: 1rem;
            }
        }

        {{ \Illuminate\Support\Facades\Cookie::get('darkmode') == '' ? '' : '
            table.dataTable tbody tr {
                background-color: #232e3c;
            }
        ' }}
    </style>
@endsection

@section('content')
    <div class="col-12">
        <div class="card">
            <a href="{{ route('mehsul.create') }}" class="btn btn-primary">Məhsul əlavə et</a>
            <div class="table-responsive">
                <table
                    class="table table-vcenter table-mobile-md card-table {{ \Illuminate\Support\Facades\Cookie::get('darkmode') }}" data-darker="{{ \Illuminate\Support\Facades\Cookie::get('darkmode') }}" id="mehsullar">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Ünvan</th>
                            <th>Partnyor</th>
                            <th>İstehsalçı</th>
                            <th>Model</th>
                            <th>Kateqoriya</th>
                            <th>Seria</th>
                            <th>Miqdar</th>
                            <th>Tarix</th>
                            <th>Topdan</th>
                            <th>Nağd</th>
                            <th>Kredit</th>
                            <th>Məhsulun statusu</th>
                            <th></th>
                            <th>barcode</th>
                        </tr>
                    </thead>

                </table>
            </div>
        </div>
    </div>

    <div class="modal modal-blur fade" id="modal-danger" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-sm modal-dialog-centered" role="document">
            <div class="modal-content">
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                <div class="modal-status bg-danger"></div>
                <div class="modal-body text-center py-4">
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon mb-2 text-danger icon-lg" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 9v2m0 4v.01" /><path d="M5 19h14a2 2 0 0 0 1.84 -2.75l-7.1 -12.25a2 2 0 0 0 -3.5 0l-7.1 12.25a2 2 0 0 0 1.75 2.75" /></svg>
                    <h3>Silmək istiyirsən?</h3>
                    <div class="text-muted">Əgər siz həqiqətən Sil düyməsinə vursanız məhsulu heç vaxt geri qaytara bilməyəcəksiniz</div>
                </div>
                <div class="modal-footer">
                    <div class="w-100">
                        <div class="row">
                            <div class="col">
                                <a href="#" class="btn btn-white w-100" data-bs-dismiss="modal">
                                    Ləğv et
                                </a>
                            </div>
                            <div class="col">
                                <form action="" method="POST" id="deleterForm">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="btn btn-danger w-100" >Sil</button>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="modal modal-blur fade" id="modal-barcode" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-sm modal-dialog-centered" role="document">
            <div class="modal-content" id="non-printable">
                <button type="button" id="close-barcode" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                <div class="modal-status bg-danger"></div>
                <div class="modal-body text-center py-4">
                    <div style="text-align: center;" id="barcode-content"></div>
                </div>
                <div class="modal-footer">
                    <div class="w-100">
                        <div class="row">
                            <div class="col">
                                <a href="javascript:void(0)" class="btn btn-white w-100" data-bs-dismiss="modal">
                                    Ləğv et
                                </a>
                            </div>
                            <div class="col">
                                <button type="submit" id="print" class="btn btn-danger w-100" >Çap et</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div id="printable"></div>
        </div>
    </div>
@endsection

@section('js')
    <script src="https://cdn.datatables.net/1.10.22/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.6.5/js/dataTables.buttons.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.6.5/js/buttons.flash.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.6.5/js/buttons.html5.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.6.5/js/buttons.print.min.js"></script>
    <script src="https://cdn.datatables.net/select/1.3.1/js/dataTables.select.min.js"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/printThis/1.15.0/printThis.min.js" integrity="sha512-d5Jr3NflEZmFDdFHZtxeJtBzk0eB+kkRXWFQqEc1EKmolXjHm2IKCA7kTvXBNjIYzjXfD5XzIjaaErpkZHCkBg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/printThis/1.15.0/printThis.js" integrity="sha512-Fd3EQng6gZYBGzHbKd52pV76dXZZravPY7lxfg01nPx5mdekqS8kX4o1NfTtWiHqQyKhEGaReSf4BrtfKc+D5w==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

    <script>
        $(document).ready(function(){
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });

            var table = $('#mehsullar');

            table.DataTable({
                processing: true,
                serverSide: true,
                ajax: {
                    url: "{{ route('mehsul.index') }}",
                },
                columns: [
                    {data: 'id', name: 'id'},
                    {data: 'magaza_id', name: 'magaza_id'},
                    {data: 'partnyor_id', name: 'partnyor_id'},
                    {data: 'istehsalchi_id', name: 'istehsalchi_id'},
                    {data: 'marka_id', name: 'marka_id'},
                    {data: 'kateqoriya_id', name: 'kateqoriya_id'},
                    {data: 'kodlasdirilmis_ad', name: 'kodlasdirilmis_ad'},
                    {data: 'miqdar', name: 'miqdar'},
                    {data: 'manual_daxiletme_tarixi', name: 'manual_daxiletme_tarixi'},
                    {data: 'topdan', name: 'topdan'},
                    {data: 'nagd', name: 'nagd'},
                    {data: 'kredit', name: 'kredit'},
                    {data: 'status', name: 'status'},
                    {data: 'action', name: 'action',searchable:false,orderable: false},
                    {data: 'barcode', name: 'barcode',searchable:false,orderable: false},
                ],
                createdRow: function( row, data, dataIndex ) {
                    $( row ).find('td:eq(0)').attr('data-label', 'id');
                    $( row ).find('td:eq(1)').attr('data-label', 'Mağaza');
                    $( row ).find('td:eq(2)').attr('data-label', 'Partnyor');
                    $( row ).find('td:eq(3)').attr('data-label', 'İstehsalçı');
                    $( row ).find('td:eq(4)').attr('data-label', 'Model');
                    $( row ).find('td:eq(5)').attr('data-label', 'Kateqoriya');
                    $( row ).find('td:eq(6)').attr('data-label', 'Seria');
                    $( row ).find('td:eq(7)').attr('data-label', 'Miqdar');
                    $( row ).find('td:eq(8)').attr('data-label', 'Tarix');
                    $( row ).find('td:eq(9)').attr('data-label', 'Topdan');
                    $( row ).find('td:eq(10)').attr('data-label', 'Nağd');
                    $( row ).find('td:eq(11)').attr('data-label', 'Kredit');
                    $( row ).find('td:eq(12)').attr('data-label', 'Status');
                    $( row ).find('td:eq(13)').attr('data-label', 'Action');
                    $( row ).find('td:eq(14)').attr('data-label', 'Barcode');
                },
                "language": {
                    "url": "//cdn.datatables.net/plug-ins/1.10.24/i18n/Azerbaijan.json"
                },
                stateSave: true,
            });

            $('#print').click(function () {
                $("#printable").printThis({
                    importCSS: true,            // import parent page css
                    importStyle: true,         // import style tags
                });
            });

        });

        $(document).on('click','.MehsulDeleter',function () {
            var id  = $(this).attr('data-id');
            let url = "/mudir/mehsul/"+id;
            $('form#deleterForm').attr('action',url);
        });

        $(document).on('click','.barcodeShower',function () {
            let id  = $(this).attr('data-id');
            var url = "{{ route('barcode-generator.show', ":id") }}";
            url = url.replace(':id', id);
            $.ajax({
                type:'GET',
                data:{id},
                url:url,
                success:function (response) {
                    $('#barcode-content').html('').html(response);
                    $('#printable').html('').html(response);
                }
            });
        });
    </script>

@endsection

3.sonra isə terminalda php:artisan make:controller mehsulController --resource yaradırıq.

<?php

namespace App\Http\Controllers\Mudir;

use App\Http\Controllers\Controller;
use App\Http\Requests\redakteMehsul;
use App\Http\Requests\yeniMehsul;
use App\Models\Istehsalchi;
use App\Models\Kateqoriya;
use App\Models\Magaza;
use App\Models\Marka;
use App\Models\Mehsul;
use App\Models\Partnyor;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Milon\Barcode\DNS1D;
use Yajra\DataTables\DataTables;

class mehsulController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        if($request->ajax())
        {
            $data = Mehsul::with('getMagaza','getPartnyor','getIstehsalchi','getMarka','getKateqoriya')
                ->latest()
                ->get();

            return DataTables::of($data)

                ->editColumn('magaza_id', function ($row) {
                    return $row->getMagaza->name;
                })

                ->editColumn('partnyor_id', function ($row) {
                    return $row->getPartnyor->name;
                })

                ->editColumn('istehsalchi_id', function ($row) {
                    return $row->getIstehsalchi->name;
                })

                ->editColumn('marka_id', function ($row) {
                    return $row->getMarka->name;
                })

                ->editColumn('kateqoriya_id', function ($row) {
                    return $row->getKateqoriya->name;
                })

                ->editColumn('manual_daxiletme_tarixi', function ($row) {
                    return Carbon::parse($row->manual_daxiletme_tarixi)->toFormattedDateString();
                })

                ->editColumn('miqdar', function ($row) {
                    return ($row->miqdar-$row->satilib).'/'.$row->miqdar;
                })

                ->editColumn('status', function ($row) {
                    return $row->status == 'satılıb' ? '<span class="badge bg-danger">Satılıb</span>' : '<span class="badge bg-success">Satılmayıb</span>';
                })

                ->addColumn('action',function ($row){
                    return $row->satilib == 0 ?'
                    <div class="btn-list flex-nowrap">
                        <a href="javascript:void(0)" class="btn btn-danger MehsulDeleter" data-id="'.$row->id.'" data-bs-toggle="modal" data-bs-target="#modal-danger">
                          <i class="fa fa-times"></i>
                        </a>
                        <a class="btn btn-info myIdeaEditor"
                        href="'.route('mehsul.edit',[$row->id]).'"><i class="fa fa-edit"></i></a>
                    </div>
                ' : '<span class="badge bg-danger">Stop action</span>';
                })

                ->addColumn('barcode',function ($row){
                    $barcode = new DNS1D();
                    return '
                        <a href="javascript:void(0)" class="btn btn-white barcodeShower" data-id="'.$row->id.'" data-bs-toggle="modal" data-bs-target="#modal-barcode">
                              <img src="data:image/png;base64,'.$barcode->getBarcodePNG('Barcode', 'C39',1,99,array(0,0,0), true).'" alt="barcode" />
                        </a>
                    ';
                })

                ->rawColumns(['status','action','barcode'])

                ->make(true);
        }

        return view('Mudir.mehsul');
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('Mudir.new-mehsul',[
            'partnyors'=>Partnyor::orderBy('id','desc')->get(),
            'istehsalchis'=>Istehsalchi::orderBy('id','desc')->get(),
            'markas'=>Marka::orderBy('id','desc')->get(),
            'kateqoriyas'=>Kateqoriya::orderBy('id','desc')->get()
        ]);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(yeniMehsul $request)
    {
        Mehsul::create([
            'magaza_id'=>2,
            'partnyor_id'=>$request->partnyor,
            'istehsalchi_id'=>$request->istehsalchi,
            'marka_id'=>$request->marka,
            'kateqoriya_id'=>$request->kateqoriya,
            'qayime_nomresi'=>$request->qayime_nomresi,
            'manual_daxiletme_tarixi'=>$request->date,
            'topdan'=>$request->topdan,
            'nagd'=>$request->nagd,
            'kredit'=>$request->kredit,
            'kodlasdirilmis_ad'=>$request->kodlasdirilmis_ad,
            'miqdar'=>$request->miqdar
        ]);

        toastr()->success('Məhsul uğurla əlavə edildi','Uğurlu əməliyyat');

        return redirect()->back()->withInput();
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $mehsul = Mehsul::whereId($id)->first();
        if ($mehsul === null)
        {
            toastr()->error('Axtarılan məhsul tapılmadı!','Xəta');
            return redirect()->back();
        }
        else
        {
            return view('Mudir.update-mehsul',[
                'mehsul'=>$mehsul,
                'magazas'=>Magaza::orderBy('id','desc')->where('id','!=',1)->get(),
                'partnyors'=>Partnyor::orderBy('id','desc')->get(),
                'istehsalchis'=>Istehsalchi::orderBy('id','desc')->get(),
                'markas'=>Marka::orderBy('id','desc')->get(),
                'kateqoriyas'=>Kateqoriya::orderBy('id','desc')->get()
            ]);
        }
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(redakteMehsul $request, $id)
    {
        $checkMehsul = Mehsul::whereId($id)->first();
        if ($checkMehsul === null)
        {
            toastr()->error('Məhsul tapılmadı 😧','Xəta');
            return redirect()->back();
        }
        else
        {
            Mehsul::whereId($id)->update([
                'magaza_id'=>$request->magaza,
                'partnyor_id'=>$request->partnyor,
                'istehsalchi_id'=>$request->istehsalchi,
                'marka_id'=>$request->marka,
                'kateqoriya_id'=>$request->kateqoriya,
                'qayime_nomresi'=>$request->qayime_nomresi,
                'manual_daxiletme_tarixi'=>$request->date,
                'topdan'=>$request->topdan,
                'nagd'=>$request->nagd,
                'kredit'=>$request->kredit,
                'kodlasdirilmis_ad'=>$request->kodlasdirilmis_ad,
                'miqdar'=>$request->miqdar
            ]);
        }

        toastr()->success('Məhsul uğurla redaktə edildi ☺','Uğurlu əməliyyat');

        return redirect()->route('mehsul.index');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $checkMehsul = Mehsul::whereId($id)->first();
        if ($checkMehsul === null)
        {
            toastr()->error('Məhsul tapılmadı 😧','Xəta');
            return redirect()->back();
        }
        else
        {
            $checkMehsul->delete();
            toastr()->success('Məhsul uğurla silindi ☺','Uğurlu əməliyyat');

            return redirect()->route('mehsul.index');
        }
    }
}

 

Digər dildə: EN