memberbaiki fungsi pada aktor manager

parent fc549bae
...@@ -44,7 +44,7 @@ return $book->stock; ...@@ -44,7 +44,7 @@ return $book->stock;
$html = $htmlBuilder $html = $htmlBuilder
->addColumn(['data' => 'title', 'name'=>'title', 'title'=>'Jenis Makanan']) ->addColumn(['data' => 'title', 'name'=>'title', 'title'=>'Jenis Makanan'])
->addColumn(['data' => 'stock', 'name'=>'amount', 'title'=>'Stock']) ->addColumn(['data' => 'stock', 'name'=>'amount', 'title'=>'Stock'])
->addColumn(['data' => 'harga', 'name'=>'harga', 'title'=>'Harga']) ->addColumn(['data' => 'harga', 'name'=>'harga', 'title'=>'harga'])
->addColumn(['data' => 'author.name', 'name'=>'author.name', 'title'=>'Pemesan']) ->addColumn(['data' => 'author.name', 'name'=>'author.name', 'title'=>'Pemesan'])
->addColumn(['data' => 'action', 'name'=>'action', 'title'=>'Action', 'orderable'=>false, 'searchable'=>false]); ->addColumn(['data' => 'action', 'name'=>'action', 'title'=>'Action', 'orderable'=>false, 'searchable'=>false]);
......
...@@ -28,7 +28,7 @@ return '<a class="btn btn-xs btn-primary" href="'.route('guest.books.borrow', $b ...@@ -28,7 +28,7 @@ return '<a class="btn btn-xs btn-primary" href="'.route('guest.books.borrow', $b
$html = $htmlBuilder $html = $htmlBuilder
->addColumn(['data' => 'title', 'name'=>'title', 'title'=>'Jenis Makanan']) ->addColumn(['data' => 'title', 'name'=>'title', 'title'=>'Jenis Makanan'])
->addColumn(['data' => 'stock', 'name'=>'stock', 'title'=>'Stock', 'orderable'=>false, 'searchable'=>false]) ->addColumn(['data' => 'stock', 'name'=>'stock', 'title'=>'Stock', 'orderable'=>false, 'searchable'=>false])
->addColumn(['data' => 'harga', 'name'=>'harga', 'title'=>'Harga']) ->addColumn(['data' => 'harga', 'name'=>'harga', 'title'=>'harga'])
->addColumn(['data' => 'author.name', 'name'=>'author.name', 'title'=>'Pemesan']) ->addColumn(['data' => 'author.name', 'name'=>'author.name', 'title'=>'Pemesan'])
->addColumn(['data' => 'action', 'name'=>'action', 'title'=>'', 'orderable'=>false, 'searchable'=>false]); ->addColumn(['data' => 'action', 'name'=>'action', 'title'=>'', 'orderable'=>false, 'searchable'=>false]);
return view('guest.index')->with(compact('html')); return view('guest.index')->with(compact('html'));
......
...@@ -4,6 +4,8 @@ namespace App\Http\Controllers; ...@@ -4,6 +4,8 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Pegawai as pegawai; use App\Pegawai as pegawai;
use App\Http\Requests\StorePegawaiRequest;
use App\Http\Requests\UpdatePegawaiRequest;
class pegawaiController extends Controller class pegawaiController extends Controller
{ {
...@@ -12,15 +14,39 @@ class pegawaiController extends Controller ...@@ -12,15 +14,39 @@ class pegawaiController extends Controller
* *
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function index() public function index(Request $request, Builder $htmlBuilder)
{ {
$data = pegawai::all(); if ($request->ajax()) {
$pegawais = pegawai::with('author');
return Datatables::of($pegawais)
->addColumn('stock', function($pegawai){
return $pegawai->stock;
})
->addColumn('action', function($pegawai){
return view('datatable._action', [
'model' => $pegawai,
'form_url' => route('pegawais.destroy', $pegawai->id),
'edit_url' => route('pegawais.edit', $pegawai->id),
'confirm_message' => 'Yakin ingin menghapus ' . $pegawai->name . '?',
return view('dashboard.admin', ['data'=> $data]); ]);
})->make(true);
}
$html = $htmlBuilder
->addColumn(['data' => 'title', 'name'=>'title', 'title'=>'Jenis Makanan'])
->addColumn(['data' => 'stock', 'name'=>'amount', 'title'=>'Stock'])
->addColumn(['data' => 'harga', 'name'=>'harga', 'title'=>'harga'])
->addColumn(['data' => 'author.name', 'name'=>'author.name', 'title'=>'Pemesan'])
->addColumn(['data' => 'action', 'name'=>'action', 'title'=>'Action', 'orderable'=>false, 'searchable'=>false]);
return view('authors.index')->with(compact('html'));
} }
/** /**
* Show the form for creating a new resource. * Show the form for creating a new resource.
* *
...@@ -28,7 +54,7 @@ class pegawaiController extends Controller ...@@ -28,7 +54,7 @@ class pegawaiController extends Controller
*/ */
public function create() public function create()
{ {
// return view('authors.create');
} }
/** /**
...@@ -37,11 +63,31 @@ class pegawaiController extends Controller ...@@ -37,11 +63,31 @@ class pegawaiController extends Controller
* @param \Illuminate\Http\Request $request * @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function store(Request $request) public function store(StorePegawaiRequest $request)
{ {
//
}
$pegawai = pegawai::create($request->except('cover'));
// isi field cover jika ada cover yang diupload
if ($request->hasFile('cover')) {
// Mengambil file yang diupload
$uploaded_cover = $request->file('cover');
// mengambil extension file
$extension = $uploaded_cover->getClientOriginalExtension();
// membuat nama file random berikut extension
$filename = md5(time()) . '.' . $extension;
// menyimpan cover ke folder public/img
$destinationPath = public_path() . DIRECTORY_SEPARATOR . 'img';
$uploaded_cover->move($destinationPath, $filename);
// mengisi field cover di pegawai dengan filename yang baru dibuat
$pegawai->cover = $filename;
$pegawai->save();
}
Session::flash("flash_notification", [
"level"=>"success",
"message"=>"Berhasil menyimpan $pegawai->name"
]);
return redirect()->route('pegawai.index');
}
/** /**
* Display the specified resource. * Display the specified resource.
* *
......
<?php
namespace App\Http\Requests\Request;
use Illuminate\Foundation\Http\FormRequest;
class StorePegawaiRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}
<?php
namespace App\Http\Requests\Request;
use Illuminate\Foundation\Http\FormRequest;
class UpdatePegawaiRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}
...@@ -25,11 +25,11 @@ class StoreBookRequest extends FormRequest ...@@ -25,11 +25,11 @@ class StoreBookRequest extends FormRequest
public function rules() public function rules()
{ {
return [ return [
'title' => 'required|unique:books,title', 'title' => 'Required',
'author_id' => 'required|exists:authors,id', 'author_id' => 'Required',
'amount' => 'numeric', 'harga' => 'Required',
'amount' => 'harga', 'amount' => 'Required',
'cover' => 'image|max:2048' 'cover' => 'Required',
]; ];
} }
} }
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StorePegawaiRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}
...@@ -6,9 +6,16 @@ class UpdateBookRequest extends StoreBookRequest ...@@ -6,9 +6,16 @@ class UpdateBookRequest extends StoreBookRequest
{ {
public function rules() public function rules()
{ {
$rules = parent::rules(); return [
$rules['title'] = 'required|unique:books,title,' . $this->route('book'); 'title' => 'Required',
return $rules; 'author_id' => 'Required',
'harga' => 'Required',
'amount' => 'Required',
'cover' => 'Required',
];
// $rules = parent::rules();
// $rules['title'] = 'required|unique:books,title,' . $this->route('book');
// return $rules;
} }
} }
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UpdatePegawaiRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}
...@@ -18,7 +18,7 @@ $table->increments('id'); ...@@ -18,7 +18,7 @@ $table->increments('id');
$table->string('title'); $table->string('title');
$table->integer('author_id')->unsigned(); $table->integer('author_id')->unsigned();
$table->integer('amount')->unsigned(); $table->integer('amount')->unsigned();
$table->integer('harga')->unsigned(); $table->string('harga');
$table->string('cover')->nullable(); $table->string('cover')->nullable();
$table->timestamps(); $table->timestamps();
$table->foreign('author_id')->references('id')->on('authors') $table->foreign('author_id')->references('id')->on('authors')
......
...@@ -12,10 +12,3 @@ ...@@ -12,10 +12,3 @@
</div> </div>
</div> </div>
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
{!! Form::label('name', 'Nama', ['class'=>'col-md-2 control-label']) !!}
<div class="col-md-4">
{!! Form::text('name', null, ['class'=>'form-control']) !!}
{!! $errors->first('name', '<p class="help-block">:message</p>') !!}
</div>
</div>
\ No newline at end of file
@extends('layouts.app') @extends('layouts.app')
@section('content') @section('content')
<section id="main-content"> <section id="main-content">
<section class="wrapper"> <section class="wrapper">
<div class="container">
<div class="row">
<br>
<div class="col-md-10">
<ul class="breadcrumb">
<li><a href="{{ url('/home') }}">Dashboard</a></li>
<li><a href="{{ url('/admin/authors') }}">Pelanggan</a></li>
<li class="active">Tambah Pelanggan</li>
</ul>
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">Tambah Pelanggan</h2>
</div>
<div class="panel-body">
{!! Form::open(['url' => route('authors.store'),
'method' => 'post', 'class'=>'form-horizontal']) !!}
@include('authors._form')
{!! Form::close() !!}
</div>
</div>
</div>
</div>
</div>
</section>
</section>
<div class="container">
<div class="row">
<br>
<div class="col-md-10">
<ul class="breadcrumb">
<li><a href="{{ url('/home') }}">Dashboard</a></li>
<li><a href="{{ url('/admin/books') }}">Pelanggan</a></li>
<li class="active">Data Pegawai</li>
</ul>
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">Data Pegawai</h2>
</div>
<div class="panel-body">
{!! Form::open(['url' => route('pegawai.store'),
'method' => 'post', 'enctype'=>'multipart/form-data','files'=>'true', 'class'=>'form-horizontal']) !!}
@include('books._form')
{!! Form::close() !!}
</div>
</div>
</div>
</div>
</div>
</section>
</section>
@endsection @endsection
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
</div> </div>
<div class="panel-body"> <div class="panel-body">
<p> <a class="btn btn-primary" href="{{ route('authors.create_pegawai') }}">Tambah</a> </p> <p> <a class="btn btn-primary" href="{{ route('authors.create') }}">Tambah</a> </p>
{!! $html->table(['class'=>'table-striped']) !!}
</div> </div>
</div> </div>
</div> </div>
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
</div> </div>
<div class="form-group{{ $errors->has('harga') ? ' has-error' : '' }}"> <div class="form-group{{ $errors->has('harga') ? ' has-error' : '' }}">
{!! Form::label('harga', 'Harga', ['class'=>'col-md-2 control-label']) !!} {!! Form::label('harga', 'harga', ['class'=>'col-md-2 control-label']) !!}
<div class="col-md-4"> <div class="col-md-4">
{!! Form::number('harga', null, ['class'=>'form-control', 'min'=>1]) !!} {!! Form::number('harga', null, ['class'=>'form-control', 'min'=>1]) !!}
{!! $errors->first('harga', '<p class="help-block">:message</p>') !!} {!! $errors->first('harga', '<p class="help-block">:message</p>') !!}
......
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