Commit f24cb7f1 by Aan Choesni Herlingga

crud master pages

parent 264d6e8b
<?php
namespace App\Http\Controllers\Webprofile\Backend;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Webprofile\Categories;
use App\Repositories\Webprofile\PagesRepository;
class PageController extends Controller
{
private $repo;
public function __construct(PagesRepository $repo)
{
$this->repo = $repo;
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
if ($request->ajax()) {
$data = $this->repo->get();
return $this->repo->datatable($data);
}
return view('webprofile.backend.pages.index')->withTitle(trans('feature.page'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
$categories = Categories::pluck('name', 'id');
$data = [
'categories' => $categories,
];
return view('webprofile.backend.pages.create', $data)->withTitle(trans('feature.create_page'));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$data = $request->except('_token');
$this->repo->store($data);
return redirect()->route('pages.index');
}
/**
* 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)
{
$data = $this->repo->findId($id);
$categories = Categories::pluck('name', 'id');
$data = [
'data' => $data,
'categories' => $categories,
];
return view('webprofile.backend.pages.edit', $data)->withTitle(trans('feature.create_page'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$data = $request->except(['_token', 'id']);
$page = $this->repo->findId($id);
$edit = $this->repo->update($data, $page);
return redirect()->route('pages.index');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$data = $this->repo->findId($id);
$this->repo->destroy($data);
return response()->json(['done']);
}
}
......@@ -5,7 +5,6 @@ namespace App\Http\Controllers\Webprofile\Backend;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Webprofile\Categories;
use App\Repositories\Webprofile\CategoryRepository;
use App\Repositories\Webprofile\PostRepository;
class PostController extends Controller
......
......@@ -13,5 +13,5 @@ class Pages extends Model
public $incrementing = false;
protected $table = 'swp_pages';
protected $fillable = [];
protected $guarded = [];
}
......@@ -35,23 +35,21 @@ class PagesRepository extends Repository
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-warning btn-round btn-sm edit">Edit</a>';
$btn = '<a href="' . url('/webprofile/pages/' . $row->id . '/edit') . '" data-toggle="tooltip" data-id="' . $row->id . '" data-original-title="' . trans('label.edit') . '" class="edit btn btn-warning btn-round btn-sm edit">' . trans('label.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-round btn-sm delete">Delete</a>';
$btn = $btn . ' <a href="javascript:void(0)" data-toggle="tooltip" data-id="' . $row->id . '" data-original-title="' . trans('label.delete') . '" class="btn btn-danger btn-round btn-sm delete">' . trans('label.delete') . '</a>';
$btn = $btn . '<br>';
return $btn;
})
->addColumn('status', function ($row) {
if ($row->is_active == true) {
$str = '<div style="color: green;"><i class="fa fa-check"></i></div>';
} else {
$str = '<div style="color: red;"><i class="fa fa-times"></i></div>';
}
->addColumn('sum', function ($row) {
$str = trans('label.viewer') . ' : ' . $row->viewer . '<br>';
$str .= trans('label.command') . ' : ' . $row->comment_count;
return $str;
})
->rawColumns(['action', 'status'])
->rawColumns(['action', 'sum'])
->make(true);
}
}
......@@ -17,7 +17,7 @@ class CreatePagesTable extends Migration
$table->string('id', 36)->primary();
$table->string('title');
$table->text('content')->nullable();
$table->string('categories', 36);
$table->string('categories', 36)->nullable();
$table->string('thumbnail')->nullable();
$table->timestamp('post_date')->nullable();
$table->boolean('post_status')->nullable();
......
......@@ -17,7 +17,7 @@ class CreatePostsTable extends Migration
$table->string('id', 36)->primary();
$table->string('title');
$table->text('content')->nullable();
$table->string('categories', 36);
$table->string('categories', 36)->nullable();
$table->string('thumbnail')->nullable();
$table->timestamp('post_date')->nullable();
$table->boolean('post_status')->nullable();
......
$(function () {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
var table = $('.data-table').DataTable({
processing: true,
serverSide: true,
responsive: true,
ajax: url,
columns: [
{ data: 'DT_RowIndex', name: 'DT_RowIndex' },
{ data: 'title', name: 'title' },
{ data: 'sum', name: 'sum' },
{ data: 'action', name: 'action', orderable: false, searchable: false },
],
columnDefs: [
{ className: 'text-center', targets: [0, 3]},
{ className: 'text-left', targets: [1, 2]},
],
});
$("body").on("click", ".delete", function (e) {
e.preventDefault();
var id = $(this).data('id');
swal({
title: "Apakah Anda Yakin?",
text: "Anda akan menghapus data ini!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
cancelButtonText: "No",
closeOnConfirm: false,
closeOnCancel: false
},
function (isConfirm) {
if (isConfirm) {
swal.close();
setTimeout(function () {
$.ajax({
dataType: 'json',
type: 'DELETE',
url: url + '/' + id,
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
}).done(function (data) {
table.draw();
swal({
title: "Data berhasil dihapus!",
type: "success",
timer: "3000"
});
});
}, 1000); // 1 second delay
}
else {
swal("Dibatalkan", "Data batal dihapus", "error");
}
}
);
});
});
$(function () {
//iCheck for checkbox and radio inputs
$('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
checkboxClass: 'icheckbox_minimal-blue',
radioClass: 'iradio_minimal-blue'
});
});
function printErrorMsg(msg) {
$(".print-error-msg").find("ul").html('');
$(".print-error-msg").css('display', 'block');
$.each(msg, function (key, value) {
$(".print-error-msg").find("ul").append('<li>' + value + '</li>');
});
}
......@@ -5,16 +5,16 @@ return [
'user' => 'User',
'category' => 'Category',
'categoryfile' => 'Category File',
'design' => 'Design',
'file' => 'File',
'gallery' => 'Gallery',
'information' => 'Information',
'design' => 'Designs',
'file' => 'Files',
'gallery' => 'Galleries',
'information' => 'Informations',
'menu' => 'Menu',
'page' => 'Page',
'post' => 'Post',
'setting' => 'Setting',
'slider' => 'Slider',
'layout' => 'Layout',
'page' => 'Pages',
'post' => 'Posts',
'setting' => 'Settings',
'slider' => 'Sliders',
'layout' => 'Layouts',
'create_category' => 'Create Category',
'create_categoryfile' => 'Create Category File',
......
......@@ -15,8 +15,8 @@
<li class="xn-openable">
<a href="#"><span class="fa fa-file"></span> <span class="xn-text">@lang('feature.page')</span></a>
<ul>
<li><a href="{{ url('webprofile/pages') }}">@lang('feature.page')</a></li>
<li><a href="{{ url('webprofile/pages/create') }}">@lang('feature.create_page')</a></li>
<li><a href="{{ url('webprofile/pages') }}">@lang('feature.page')</a></li>
</ul>
</li>
<li>
......
@extends('webprofile.backend.layouts.master')
@section('title')
{{ $title }}
@stop
@section('assets')
<link rel="stylesheet" href="{!! asset('backend/assets/select2/select2.min.css') !!}">
<style media="screen">
.tkh{
color: black;
}
</style>
@stop
@section('breadcrumbs')
<li><a href="{{URL::to('dashboard')}}">@lang('label.dashboard')</a></li>
<li class="active">@lang('feature.create_page')</li>
@stop
@section('content')
<!-- page start-->
<div class="row">
{!! Form::open(array('url' => route('pages.store'), 'method' => 'POST', 'id' => 'pages', 'files' => true)) !!}
{!! csrf_field() !!}
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><strong>@lang('label.create')</strong> @lang('feature.page')</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<div class="form-group @if ($errors->has('title')) has-error @endif">
<div class="col-md-12">
{{ Form::text('title', old('title'), array('class' => 'form-control', 'placeholder'=>app('translator')->getFromJson('label.title'), 'style'=>'font-size: 14pt;')) }}
@if ($errors->has('title'))
<label id="login-error" class="error" for="login">{{$errors->first('title')}}</label>
@endif
</div>
</div>
</div>
<div class="col-md-12">
<div class="block">
{{ Form::textarea('content', null, array('id'=>'content')) }}
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-footer">
<button class="btn btn-info pull-right">@lang('label.save')</button>
</div>
</div>
</div>
{!! Form::close() !!}
</div>
<!-- page end-->
@stop
@section('script')
{!! Html::script('backend/assets/select2/select2.full.min.js') !!}
{!! Html::script('backend/js/plugins/bootstrap/bootstrap-datepicker.js') !!}
{!! Html::script('backend/js/plugins/bootstrap/bootstrap-timepicker.min.js') !!}
{!! Html::script('backend/js/plugins/bootstrap/bootstrap-file-input.js') !!}
{!! Html::script('backend/js/plugins/summernote/summernote.js') !!}
<script type="text/javascript">
function PreviewImage() {
var oFReader = new FileReader();
oFReader.readAsDataURL(document.getElementById("uploadImage").files[0]);
oFReader.onload = function (oFREvent) {
document.getElementById("uploadPreview").src = oFREvent.target.result;
};
};
$(document).ready(function() {
$('#content').summernote({
height: 400
});
});
$('#categories').select2();
</script>
@stop
@extends('webprofile.backend.layouts.master')
@section('title')
{{ $title }}
@stop
@section('assets')
<link rel="stylesheet" href="{!! asset('backend/assets/select2/select2.min.css') !!}">
<style media="screen">
.tkh{
color: black;
}
</style>
@stop
@section('breadcrumbs')
<li><a href="{{URL::to('dashboard')}}">@lang('label.dashboard')</a></li>
<li class="active">@lang('feature.create_post')</li>
@stop
@section('content')
<!-- page start-->
<div class="row">
{!! Form::model($data, ['route' => ['pages.update', $data->id], 'method'=>'patch', 'files' => true]) !!}
{!! csrf_field() !!}
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><strong>@lang('label.create')</strong> @lang('feature.page')</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<div class="form-group @if ($errors->has('title')) has-error @endif">
<div class="col-md-12">
{{ Form::text('title', old('title'), array('class' => 'form-control', 'placeholder'=>app('translator')->getFromJson('label.title'), 'style'=>'font-size: 14pt;')) }}
@if ($errors->has('title'))
<label id="login-error" class="error" for="login">{{$errors->first('title')}}</label>
@endif
</div>
</div>
</div>
<div class="col-md-12">
<div class="block">
{{ Form::textarea('content', null, array('id'=>'content')) }}
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-footer">
<button class="btn btn-info pull-right">@lang('label.save')</button>
</div>
</div>
</div>
{!! Form::close() !!}
</div>
<!-- page end-->
@stop
@section('script')
{!! Html::script('backend/assets/select2/select2.full.min.js') !!}
{!! Html::script('backend/js/plugins/bootstrap/bootstrap-datepicker.js') !!}
{!! Html::script('backend/js/plugins/bootstrap/bootstrap-timepicker.min.js') !!}
{!! Html::script('backend/js/plugins/bootstrap/bootstrap-file-input.js') !!}
{!! Html::script('backend/js/plugins/summernote/summernote.js') !!}
<script type="text/javascript">
function PreviewImage() {
var oFReader = new FileReader();
oFReader.readAsDataURL(document.getElementById("uploadImage").files[0]);
oFReader.onload = function (oFREvent) {
document.getElementById("uploadPreview").src = oFREvent.target.result;
};
};
$(document).ready(function() {
$('#content').summernote({
height: 400
});
});
$('#categories').select2();
</script>
@stop
@extends('webprofile.backend.layouts.master')
@section('assets')
<link rel="stylesheet" href="{!! asset('backend/js/datatables.net-bs/css/dataTables.bootstrap.min.css') !!}">
<meta name="csrf-token" content="{{ csrf_token() }}">
@endsection
@section('title')
{{ $title }}
@stop
@section('breadcrumbs')
<li><a href="{{URL::to('dashboard')}}">@lang('label.dashboard')</a></li>
<li class="active">@lang('feature.post')</li>
@stop
@section('content')
<!-- page start-->
<div class="row">
<div class="col-lg-12">
<!-- START DEFAULT DATATABLE -->
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">{!! $title !!}</h3>
<a class="btn btn-info" href="{{URL::to('webprofile/pages/create')}}" style="margin: 0cm 0px 0cm 10px;">@lang('label.create')</a>
<ul class="panel-controls">
<li><a href="#" class="panel-collapse"><span class="fa fa-angle-down"></span></a></li>
</ul>
</div>
<div class="panel-body">
<table class="table table-hover data-table" width="100%">
<thead>
<tr>
<th width="5%" style="text-align: center;">@lang('label.number')</th>
<th style="text-align: center;">@lang('label.title')</th>
<th width="20%" style="text-align: center;">@lang('label.sum')</th>
<th align="center" width="10%" style="text-align: center;">@lang('label.action')</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
<!-- END DEFAULT DATATABLE -->
</div>
</div>
<!-- page end-->
@stop
@section('script')
<script src="{!!asset('backend/js/datatables.net/js/jquery.dataTables.min.js') !!}"></script>
<script src="{!!asset('backend/js/datatables.net-bs/js/dataTables.bootstrap.min.js') !!}"></script>
<script src="{{ url('backend/assets/plugins/jquery-datatable/buttons/dataTables.buttons.min.js') }}"></script>
<script src="{{ url('backend/assets/plugins/jquery-datatable/buttons/buttons.bootstrap4.min.js') }}"></script>
<script src="{{ url('backend/assets/plugins/jquery-datatable/buttons/buttons.colVis.min.js') }}"></script>
<script src="{{ url('backend/assets/plugins/jquery-datatable/buttons/buttons.html5.min.js') }}"></script>
<script src="{{ url('backend/assets/plugins/jquery-datatable/buttons/buttons.print.min.js') }}"></script>
<script>
var url = "{{ route('pages.index') }}";
</script>
{{ Html::script('js/master/page.js') }}
@stop
......@@ -4,6 +4,7 @@ Route::group(['middleware' => 'auth'], function () {
Route::group(['namespace' => 'Webprofile\Backend', 'prefix' => 'webprofile'], function () {
Route::resource('category', 'CategoryController');
Route::resource('posts', 'PostController');
Route::resource('pages', 'PageController');
});
// });
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment