Created
June 18, 2020 05:01
-
-
Save fleetimee/2b4a207452f60fd46586afc9acebb8c0 to your computer and use it in GitHub Desktop.
Datatables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
@yield('title') | |
<meta name="csrf-token" content="{{ csrf_token() }}"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" href="{{ asset('adminLTE/plugins/fontawesome-free/css/all.min.css') }}"> | |
<link rel="stylesheet" href="{{ asset('adminLTE/dist/css/adminlte.min.css') }}"> | |
<link rel="stylesheet" href="{{ asset('adminLTE/plugins/select2/css/select2.min.css') }}"> | |
<link rel="stylesheet" href="{{ asset('adminLTE/plugins/tempusdominus-bootstrap-4/css/tempusdominus-bootstrap-4.min.css') }}"> | |
<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css"> | |
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700"> | |
<link href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet"> | |
<link href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css" rel="stylesheet"> | |
<link rel="stylesheet" href="{{ asset('css/myStyle.css') }}"> | |
@yield('css') | |
</head> | |
<body class="hold-transition sidebar-mini"> | |
<div class="wrapper"> | |
<nav class="main-header navbar navbar-expand navbar-white navbar-light"> | |
<ul class="navbar-nav"> | |
<li class="nav-item"> | |
<a class="nav-link" data-widget="pushmenu" href="#"><i class="fas fa-bars"></i></a> | |
</li> | |
<li class="nav-item d-none d-sm-inline-block"> | |
<a href="#" class="nav-link">Home</a> | |
</li> | |
<li class="nav-item d-none d-sm-inline-block"> | |
<a href="#" class="nav-link">Contact</a> | |
</li> | |
</ul> | |
<form class="form-inline ml-3"> | |
<div class="input-group input-group-sm"> | |
<input class="form-control form-control-navbar" type="search" placeholder="Search" aria-label="Search"> | |
<div class="input-group-append"> | |
<button class="btn btn-navbar" type="submit"> | |
<i class="fas fa-search"></i> | |
</button> | |
</div> | |
</div> | |
</form> | |
<ul class="navbar-nav ml-auto"> | |
<li class="nav-item dropdown"> | |
<a class="nav-link" data-toggle="dropdown" href="#"> | |
<i class="far fa-comments"></i> | |
<span class="badge badge-danger navbar-badge">3</span> | |
</a> | |
<div class="dropdown-menu dropdown-menu-lg dropdown-menu-right"> | |
<a href="#" class="dropdown-item"> | |
<div class="media"> | |
<img src="../../dist/img/user1-128x128.jpg" alt="User Avatar" class="img-size-50 mr-3 img-circle"> | |
<div class="media-body"> | |
<h3 class="dropdown-item-title"> | |
Brad Diesel | |
<span class="float-right text-sm text-danger"><i class="fas fa-star"></i></span> | |
</h3> | |
<p class="text-sm">Call me whenever you can...</p> | |
<p class="text-sm text-muted"><i class="far fa-clock mr-1"></i> 4 Hours Ago</p> | |
</div> | |
</div> | |
</a> | |
<div class="dropdown-divider"></div> | |
<a href="#" class="dropdown-item-title"> | |
<div class="media"> | |
<img src="../../dist/img/user8-128x128.jpg" alt="User Avatar" class="img-size-50 img-circle mr-3"> | |
<div class="media-body"> | |
<h3 class="dropdown-item-title"> | |
John Pierce | |
<span class="float-right text-sm text-muted"><i class="fas fa-star"></i></span> | |
</h3> | |
<p class="text-sm">I got your message bro</p> | |
<p class="text-sm text-muted"><i class="far fa-clock mr-1"></i> 4 Hours Ago</p> | |
</div> | |
</div> | |
</a> | |
<div class="dropdown-divider"></div> | |
<a href="#" class="dropdown-item"> | |
<div class="media"> | |
<img src="../../dist/img/user3-128x128.jpg" alt="User Avatar" class="img-size-50 img-circle mr-3"> | |
<div class="media-body"> | |
<h3 class="dropdown-item-title"> | |
Nora Silvester | |
<span class="float-right text-sm text-warning"><i class="fas fa-star"></i></span> | |
</h3> | |
<p class="text-sm">The subject goes here</p> | |
<p class="text-sm text-muted"><i class="far fa-clock mr-1"></i> 4 Hours Ago</p> | |
</div> | |
</div> | |
</a> | |
<div class="dropdown-divider"></div> | |
<a href="#" class="dropdown-item dropdown-footer">See All Messages</a> | |
</div> | |
</li> | |
<li class="nav-item dropdown"> | |
<a class="nav-link" data-toggle="dropdown" href="#"> | |
<i class="far fa-bell"></i> | |
<span class="badge badge-warning navbar-badge">15</span> | |
</a> | |
<div class="dropdown-menu dropdown-menu-lg dropdown-menu-right"> | |
<span class="dropdown-item dropdown-header">15 Notifications</span> | |
<div class="dropdown-divider"></div> | |
<a href="#" class="dropdown-item"> | |
<i class="fas fa-envelope mr-2"></i> 4 new messages | |
<span class="float-right text-muted text-sm">3 mins</span> | |
</a> | |
<div class="dropdown-divider"></div> | |
<a href="#" class="dropdown-item"> | |
<i class="fas fa-users mr-2"></i> 8 friend requests | |
<span class="float-right text-muted text-sm">12 hours</span> | |
</a> | |
<div class="dropdown-divider"></div> | |
<a href="#" class="dropdown-item"> | |
<i class="fas fa-file mr-2"></i> 3 new reports | |
<span class="float-right text-muted text-sm">2 days</span> | |
</a> | |
<div class="dropdown-divider"></div> | |
<a href="#" class="dropdown-item dropdown-footer">See All Notifications</a> | |
</div> | |
</li> | |
<li class="nav-item"> | |
<a class="nav-link" data-widget="control-sidebar" data-slide="true" href="#"> | |
<i class="fas fa-th-large"></i> | |
</a> | |
</li> | |
</ul> | |
</nav> | |
@include('layout.admin.sidebarAdmin') | |
<div class="content-wrapper"> | |
@yield('content') | |
</div> | |
<footer class="main-footer"> | |
<div class="float-right d-none d-sm-block"> | |
<b>Version</b> 3.0.2 | |
</div> | |
<strong>Copyright © 2014-2019 <a href="http://adminlte.io">AdminLTE.io</a>.</strong> All rights reserved. | |
</footer> | |
<aside class="control-sidebar control-sidebar-dark"></aside> | |
</div> | |
<script src="{{ asset('js/jquery.min.js') }}"></script> | |
<script src="{{ asset('js/bootstrap.bundle.min.js') }}"></script> | |
<script src="{{ asset('js/adminlte.min.js') }}"></script> | |
<script src="{{ asset('js/demo.js') }}"></script> | |
<script src="{{ asset('adminLTE/plugins/select2/js/select2.full.min.js') }}"></script> | |
<script src="{{ asset('adminLTE/plugins/tempusdominus-bootstrap-4/js/tempusdominus-bootstrap-4.min.js') }}"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.0/jquery.validate.js"></script> | |
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script> | |
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script> | |
<script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script> | |
<script type="text/javascript"> | |
$(function () { | |
$.ajaxSetup({ | |
headers: { | |
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') | |
} | |
}); | |
var table = $('#anjing').DataTable({ | |
processing: true, | |
serverSide: true, | |
ajax: "{{ route('kategori.index') }}", | |
columns: [ | |
{data: 'DT_RowIndex', name: 'DT_RowIndex'}, | |
{data: 'nama', name: 'nama'}, | |
{data: 'parent_id', name: 'parent_id'}, | |
{data: 'action', name: 'action', orderable: false, searchable: false}, | |
] | |
}) | |
}); | |
</script> | |
@yield('js') | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return [ | |
/* | |
|-------------------------------------------------------------------------- | |
| Application Name | |
|-------------------------------------------------------------------------- | |
| | |
| This value is the name of your application. This value is used when the | |
| framework needs to place the application's name in a notification or | |
| any other location as required by the application or its packages. | |
| | |
*/ | |
'name' => env('APP_NAME', 'Laravel'), | |
/* | |
|-------------------------------------------------------------------------- | |
| Application Environment | |
|-------------------------------------------------------------------------- | |
| | |
| This value determines the "environment" your application is currently | |
| running in. This may determine how you prefer to configure various | |
| services the application utilizes. Set this in your ".env" file. | |
| | |
*/ | |
'env' => env('APP_ENV', 'production'), | |
/* | |
|-------------------------------------------------------------------------- | |
| Application Debug Mode | |
|-------------------------------------------------------------------------- | |
| | |
| When your application is in debug mode, detailed error messages with | |
| stack traces will be shown on every error that occurs within your | |
| application. If disabled, a simple generic error page is shown. | |
| | |
*/ | |
'debug' => (bool) env('APP_DEBUG', false), | |
/* | |
|-------------------------------------------------------------------------- | |
| Application URL | |
|-------------------------------------------------------------------------- | |
| | |
| This URL is used by the console to properly generate URLs when using | |
| the Artisan command line tool. You should set this to the root of | |
| your application so that it is used when running Artisan tasks. | |
| | |
*/ | |
'url' => env('APP_URL', 'http://localhost'), | |
'asset_url' => env('ASSET_URL', null), | |
/* | |
|-------------------------------------------------------------------------- | |
| Application Timezone | |
|-------------------------------------------------------------------------- | |
| | |
| Here you may specify the default timezone for your application, which | |
| will be used by the PHP date and date-time functions. We have gone | |
| ahead and set this to a sensible default for you out of the box. | |
| | |
*/ | |
'timezone' => 'UTC', | |
/* | |
|-------------------------------------------------------------------------- | |
| Application Locale Configuration | |
|-------------------------------------------------------------------------- | |
| | |
| The application locale determines the default locale that will be used | |
| by the translation service provider. You are free to set this value | |
| to any of the locales which will be supported by the application. | |
| | |
*/ | |
'locale' => 'en', | |
/* | |
|-------------------------------------------------------------------------- | |
| Application Fallback Locale | |
|-------------------------------------------------------------------------- | |
| | |
| The fallback locale determines the locale to use when the current one | |
| is not available. You may change the value to correspond to any of | |
| the language folders that are provided through your application. | |
| | |
*/ | |
'fallback_locale' => 'en', | |
/* | |
|-------------------------------------------------------------------------- | |
| Faker Locale | |
|-------------------------------------------------------------------------- | |
| | |
| This locale will be used by the Faker PHP library when generating fake | |
| data for your database seeds. For example, this will be used to get | |
| localized telephone numbers, street address information and more. | |
| | |
*/ | |
'faker_locale' => 'en_US', | |
/* | |
|-------------------------------------------------------------------------- | |
| Encryption Key | |
|-------------------------------------------------------------------------- | |
| | |
| This key is used by the Illuminate encrypter service and should be set | |
| to a random, 32 character string, otherwise these encrypted strings | |
| will not be safe. Please do this before deploying an application! | |
| | |
*/ | |
'key' => env('APP_KEY'), | |
'cipher' => 'AES-256-CBC', | |
/* | |
|-------------------------------------------------------------------------- | |
| Autoloaded Service Providers | |
|-------------------------------------------------------------------------- | |
| | |
| The service providers listed here will be automatically loaded on the | |
| request to your application. Feel free to add your own services to | |
| this array to grant expanded functionality to your applications. | |
| | |
*/ | |
'providers' => [ | |
/* | |
* Laravel Framework Service Providers... | |
*/ | |
Illuminate\Auth\AuthServiceProvider::class, | |
Illuminate\Broadcasting\BroadcastServiceProvider::class, | |
Illuminate\Bus\BusServiceProvider::class, | |
Illuminate\Cache\CacheServiceProvider::class, | |
Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class, | |
Illuminate\Cookie\CookieServiceProvider::class, | |
Illuminate\Database\DatabaseServiceProvider::class, | |
Illuminate\Encryption\EncryptionServiceProvider::class, | |
Illuminate\Filesystem\FilesystemServiceProvider::class, | |
Illuminate\Foundation\Providers\FoundationServiceProvider::class, | |
Illuminate\Hashing\HashServiceProvider::class, | |
Illuminate\Mail\MailServiceProvider::class, | |
Illuminate\Notifications\NotificationServiceProvider::class, | |
Illuminate\Pagination\PaginationServiceProvider::class, | |
Illuminate\Pipeline\PipelineServiceProvider::class, | |
Illuminate\Queue\QueueServiceProvider::class, | |
Illuminate\Redis\RedisServiceProvider::class, | |
Illuminate\Auth\Passwords\PasswordResetServiceProvider::class, | |
Illuminate\Session\SessionServiceProvider::class, | |
Illuminate\Translation\TranslationServiceProvider::class, | |
Illuminate\Validation\ValidationServiceProvider::class, | |
Illuminate\View\ViewServiceProvider::class, | |
Yajra\DataTables\DataTablesServiceProvider::class, | |
/* | |
* Package Service Providers... | |
*/ | |
/* | |
* Application Service Providers... | |
*/ | |
App\Providers\AppServiceProvider::class, | |
App\Providers\AuthServiceProvider::class, | |
// App\Providers\BroadcastServiceProvider::class, | |
App\Providers\EventServiceProvider::class, | |
App\Providers\RouteServiceProvider::class, | |
], | |
/* | |
|-------------------------------------------------------------------------- | |
| Class Aliases | |
|-------------------------------------------------------------------------- | |
| | |
| This array of class aliases will be registered when this application | |
| is started. However, feel free to register as many as you wish as | |
| the aliases are "lazy" loaded so they don't hinder performance. | |
| | |
*/ | |
'aliases' => [ | |
'App' => Illuminate\Support\Facades\App::class, | |
'Arr' => Illuminate\Support\Arr::class, | |
'Artisan' => Illuminate\Support\Facades\Artisan::class, | |
'Auth' => Illuminate\Support\Facades\Auth::class, | |
'Blade' => Illuminate\Support\Facades\Blade::class, | |
'Broadcast' => Illuminate\Support\Facades\Broadcast::class, | |
'Bus' => Illuminate\Support\Facades\Bus::class, | |
'Cache' => Illuminate\Support\Facades\Cache::class, | |
'Config' => Illuminate\Support\Facades\Config::class, | |
'Cookie' => Illuminate\Support\Facades\Cookie::class, | |
'Crypt' => Illuminate\Support\Facades\Crypt::class, | |
'DB' => Illuminate\Support\Facades\DB::class, | |
'Eloquent' => Illuminate\Database\Eloquent\Model::class, | |
'Event' => Illuminate\Support\Facades\Event::class, | |
'File' => Illuminate\Support\Facades\File::class, | |
'Gate' => Illuminate\Support\Facades\Gate::class, | |
'Hash' => Illuminate\Support\Facades\Hash::class, | |
'Http' => Illuminate\Support\Facades\Http::class, | |
'Lang' => Illuminate\Support\Facades\Lang::class, | |
'Log' => Illuminate\Support\Facades\Log::class, | |
'Mail' => Illuminate\Support\Facades\Mail::class, | |
'Notification' => Illuminate\Support\Facades\Notification::class, | |
'Password' => Illuminate\Support\Facades\Password::class, | |
'Queue' => Illuminate\Support\Facades\Queue::class, | |
'Redirect' => Illuminate\Support\Facades\Redirect::class, | |
'Redis' => Illuminate\Support\Facades\Redis::class, | |
'Request' => Illuminate\Support\Facades\Request::class, | |
'Response' => Illuminate\Support\Facades\Response::class, | |
'Route' => Illuminate\Support\Facades\Route::class, | |
'Schema' => Illuminate\Support\Facades\Schema::class, | |
'Session' => Illuminate\Support\Facades\Session::class, | |
'Storage' => Illuminate\Support\Facades\Storage::class, | |
'Str' => Illuminate\Support\Str::class, | |
'URL' => Illuminate\Support\Facades\URL::class, | |
'Validator' => Illuminate\Support\Facades\Validator::class, | |
'View' => Illuminate\Support\Facades\View::class, | |
'DataTables' => Yajra\DataTables\Facades\DataTables::class, | |
], | |
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@extends('layout.admin') | |
@section('title') | |
<title>Kategori</title> | |
@endsection | |
@section('content') | |
<main class="main"> | |
<ol class="breadcrumb"> | |
<li class="breadcrumb-item">Home</li> | |
<li class="breadcrumb-item active">Kategori</li> | |
</ol> | |
<div class="container-fluid"> | |
<div class="animated fadeIn"> | |
<div class="card"> | |
<div class="card-header"> | |
<h4 class="card-title">List Kategori</h4> | |
</div> | |
<div class="card-body"> | |
@if (session('success')) | |
<div class="alert alert-success">{{ session('success') }}</div> | |
@endif | |
@if (session('error')) | |
<div class="alert alert-danger">{{ session('error') }}</div> | |
@endif | |
<a class="btn btn-success my-4" href="javascript:void(0)" id="createNewProduct"> Create New Product</a> | |
<div class="table-responsive"> | |
<table id="anjing" class="table table-hover table-bordered data-table"> | |
<thead> | |
<tr> | |
<th>#</th> | |
<th>Kategori</th> | |
<th>Parent</th> | |
<th>Created At</th> | |
<th>Aksi</th> | |
</tr> | |
</thead> | |
<tbody> | |
</tbody> | |
</table> | |
</div> | |
{!! $kategori->links() !!} | |
</div> | |
</div> | |
</div> | |
</div> | |
</main> | |
@endsection | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use Illuminate\Http\Request; | |
use App\Kategori; | |
use DataTables; | |
class kategoriController extends Controller | |
{ | |
public function index(Request $request) | |
{ | |
if ($request->ajax()) { | |
$data = Kategori::latest()->get(); | |
return DataTables::of($data) | |
->addIndexColumn() | |
->addColumn('action', function($row){ | |
$btn = '<a href="javascript:void(0)" data-toggle="tooltip" data-id="'.$row->id.'" data-original-title="Edit" class="edit btn btn-primary btn-sm editProduct">Edit</a>'; | |
$btn = $btn.' <a href="javascript:void(0)" data-toggle="tooltip" data-id="'.$row->id.'" data-original-title="Delete" class="btn btn-danger btn-sm deleteProduct">Delete</a>'; | |
return $btn; | |
}) | |
->rawColumns(['action']) | |
->make(true); | |
} | |
$kategori = Kategori::with(['parent'])->orderBy('nama', 'DESC')->paginate(10); | |
$parent = Kategori::getParent()->orderBy('nama', 'ASC')->get(); | |
return view('kategori.index', compact('kategori', 'parent')); | |
} | |
public function store(Request $request) | |
{ | |
$this->validate($request, [ | |
'nama' => 'required|string|max:50|unique:kategoris' | |
]); | |
$request->request->add(['slug' => $request->nama]); | |
Kategori::create($request->except('_token')); | |
return redirect(route('kategori.index'))->with(['success' => 'Kategori berhasil di tambah']); | |
} | |
public function edit($id) | |
{ | |
$kategori = Kategori::find($id); | |
$parent = Kategori::getParent()->orderBy('nama', 'ASC')->get(); | |
return view('kategori.edit', compact('kategori', 'parent')); | |
} | |
public function update(Request $request, $id) | |
{ | |
$this->validate($request, [ | |
'nama' => 'required|string|max:50|unique:kategoris,nama,' . $id | |
]); | |
$kategori = Kategori::find($id); | |
$kategori->update([ | |
'nama' => $request->nama, | |
'slug' => $request->nama, | |
'parent_id' => $request->parent_id | |
]); | |
return redirect(route('kategori.index'))->with(['success' => 'Kategori telah di update']); | |
} | |
public function destroy($id) | |
{ | |
$kategori = Kategori::withCount(['child', 'produk'])->find($id); | |
if ($kategori->child_count == 0 && $kategori->produk_count == 0) { | |
$kategori->delete(); | |
return redirect(route('kategori.index'))->with(['success' => 'Kategori telah di hapus']); | |
} | |
return redirect(route('kategori.index'))->with(['error' => 'Kategori Ini Memiliki Anak Kategori']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment