memberbaiki fungsi pada aktor manager

parent fc549bae
......@@ -44,7 +44,7 @@ return $book->stock;
$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' => '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]);
......
......@@ -28,7 +28,7 @@ return '<a class="btn btn-xs btn-primary" href="'.route('guest.books.borrow', $b
$html = $htmlBuilder
->addColumn(['data' => 'title', 'name'=>'title', 'title'=>'Jenis Makanan'])
->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' => 'action', 'name'=>'action', 'title'=>'', 'orderable'=>false, 'searchable'=>false]);
return view('guest.index')->with(compact('html'));
......
......@@ -4,6 +4,8 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Pegawai as pegawai;
use App\Http\Requests\StorePegawaiRequest;
use App\Http\Requests\UpdatePegawaiRequest;
class pegawaiController extends Controller
{
......@@ -12,15 +14,39 @@ class pegawaiController extends Controller
*
* @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.
*
......@@ -28,7 +54,7 @@ class pegawaiController extends Controller
*/
public function create()
{
//
return view('authors.create');
}
/**
......@@ -37,11 +63,31 @@ class pegawaiController extends Controller
* @param \Illuminate\Http\Request $request
* @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.
*
......
<?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
public function rules()
{
return [
'title' => 'required|unique:books,title',
'author_id' => 'required|exists:authors,id',
'amount' => 'numeric',
'amount' => 'harga',
'cover' => 'image|max:2048'
'title' => 'Required',
'author_id' => 'Required',
'harga' => 'Required',
'amount' => 'Required',
'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
{
public function rules()
{
$rules = parent::rules();
$rules['title'] = 'required|unique:books,title,' . $this->route('book');
return $rules;
return [
'title' => 'Required',
'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');
$table->string('title');
$table->integer('author_id')->unsigned();
$table->integer('amount')->unsigned();
$table->integer('harga')->unsigned();
$table->string('harga');
$table->string('cover')->nullable();
$table->timestamps();
$table->foreign('author_id')->references('id')->on('authors')
......
......@@ -12,10 +12,3 @@
</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')
@section('content')
<section id="main-content">
<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>
<section id="main-content">
<section class="wrapper">
<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
......@@ -20,8 +20,8 @@
</div>
<div class="panel-body">
<p> <a class="btn btn-primary" href="{{ route('authors.create_pegawai') }}">Tambah</a> </p>
{!! $html->table(['class'=>'table-striped']) !!}
<p> <a class="btn btn-primary" href="{{ route('authors.create') }}">Tambah</a> </p>
</div>
</div>
</div>
......
......@@ -18,7 +18,7 @@
</div>
<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">
{!! Form::number('harga', null, ['class'=>'form-control', 'min'=>1]) !!}
{!! $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