Commit 4af52e65 by jhon

Crud Barang

parent 5ae9f5d2
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Barang extends Model
{
protected $fillable = [
'nama', 'jumlah', 'harga','deskripsi','kategori','gambar',
];
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Barang;
class InventoriController extends Controller
{
public function ListBarang()
{
return view('adminlte::inventori.ListBarang.index');
$barangs = Barang::all();
return view('adminlte::inventori.ListBarang.index', compact('barangs'));
}
public function create()
{
return view('adminlte::inventori.ListBarang.create');
}
public function store(Request $request)
{
$this->validate($request, [
'nama' => 'required',
'jumlah' => 'required',
'harga' => 'required',
'deskripsi' => 'required',
'kategori' => 'required',
'gambar' => 'required',
]);
$barangs = new Barang();
$barangs->nama = $request['nama'];
$barangs->jumlah = $request['jumlah'];
$barangs->harga = $request['harga'];
$barangs->deskripsi = $request['deskripsi'];
$barangs->kategori = $request['kategori'];
$barangs->gambar = $request['gambar'];
$barangs->save();
return redirect('ListBarang');
}
public function edit($id)
{
$barangs = Barang::where('id', $id)->first();
return view('adminlte::inventori.ListBarang.edit')->with('barangs', $barangs);
}
public function update(Request $request, $id)
{
$this->validate($request, [
'nama' => 'required',
'jumlah' => 'required',
'harga' => 'required',
'deskripsi' => 'required',
'kategori' => 'required',
'gambar' => 'required',
]);
$barangs = Barang::findOrFail($id);
$barangs->nama = $request->nama;
$barangs->jumlah = $request->jumlah;
$barangs->harga = $request->harga;
$barangs->deskripsi = $request->deskripsi;
$barangs->kategori = $request->kategori;
$barangs->gambar = $request->gambar;
$barangs->save();
return redirect('ListBarang');
}
public function destroy($id)
{
$barangs = Barang::find($id);
$barangs->delete();
return redirect('ListBarang');
}
public function ListRequest()
{
return view('adminlte::inventori.ListRequest.index');
......
@extends('adminlte::layouts.app')
@section('htmlheader_title')
Create
@endsection
@section('contentheader_title')
Page Create List Barang
@endsection
@section('main-content')
<div class="container">
<div class="col-md-8 col-md-offset-2">
<div class="panel-body">
<form class="form-horizontal" action="{{ url('store') }}" method="POST">
{!! csrf_field() !!}
<div class="form-group{{ $errors->has('nama') ? ' has-error' : '' }}">
<label for="title" class="col-md-4 control-label">Nama</label>
<div class="col-md-6">
<input type="text" class="form-control" name="nama" value="{{ old('nama') }}" >
@if ($errors->has('nama'))
<span class="help-block">
<strong>{{ $errors->first('nama') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('jumlah') ? ' has-error' : '' }}">
<label for="title" class="col-md-4 control-label">Jumlah</label>
<div class="col-md-6">
<input type="text" class="form-control" name="jumlah" value="{{ old('jumlah') }}" >
@if ($errors->has('jumlah'))
<span class="help-block">
<strong>{{ $errors->first('jumlah') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('harga') ? ' has-error' : '' }}">
<label for="title" class="col-md-4 control-label">Harga</label>
<div class="col-md-6">
<input type="text" class="form-control" name="harga" value="{{ old('harga') }}" >
@if ($errors->has('harga'))
<span class="help-block">
<strong>{{ $errors->first('harga') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('deskripsi') ? ' has-error' : '' }}">
<label for="title" class="col-md-4 control-label">Deskripsi</label>
<div class="col-md-6">
<input type="text" class="form-control" name="deskripsi" value="{{ old('deskripsi') }}" >
@if ($errors->has('deskripsi'))
<span class="help-block">
<strong>{{ $errors->first('deskripsi') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('kategori') ? ' has-error' : '' }}">
<label for="title" class="col-md-4 control-label">Kategori</label>
<div class="col-md-6">
<select name="kategori" class="form-control">
<option value="makanan">Makanan</option>
<option value="minuman">Minuman</option>
<option value="alat tulis">Alat Tulis</option>
<option value="alat mandi">Alat Mandi</option>
</select>
@if ($errors->has('kategori'))
<span class="help-block">
<strong>{{ $errors->first('kategori') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('gambar') ? ' has-error' : '' }}">
<label for="title" class="col-md-4 control-label">Gambar</label>
<div class="col-md-6">
<input type="text" class="form-control" name="gambar" value="{{ old('gambar') }}" >
@if ($errors->has('gambar'))
<span class="help-block">
<strong>{{ $errors->first('gambar') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<button type="submit" class="btn btn-primary">
Tambah
</button>
</div>
</div>
</form>
</div>
</div>
</div>
@endsection
\ No newline at end of file
@extends('adminlte::layouts.app')
@section('htmlheader_title')
Edit
@endsection
@section('contentheader_title')
Page Edit Request
@endsection
@section('main-content')
<div class="container">
<div class="col-md-8 col-md-offset-2">
<div class="panel-body">
<form class="form-horizontal" action="{{ url('update', $barangs->id) }}" method="POST">
{!! csrf_field() !!}
<div class="form-group{{ $errors->has('nama') ? ' has-error' : '' }}">
<label for="title" class="col-md-4 control-label">Nama</label>
<div class="col-md-6">
<input type="text" class="form-control" name="nama" value="{{ $barangs->nama}}" >
@if ($errors->has('nama'))
<span class="help-block">
<strong>{{ $errors->first('nama') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('jumlah') ? ' has-error' : '' }}">
<label for="title" class="col-md-4 control-label">Jumlah</label>
<div class="col-md-6">
<input type="text" class="form-control" name="jumlah" value="{{ $barangs->jumlah}}" >
@if ($errors->has('jumlah'))
<span class="help-block">
<strong>{{ $errors->first('jumlah') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('harga') ? ' has-error' : '' }}">
<label for="title" class="col-md-4 control-label">Harga</label>
<div class="col-md-6">
<input type="text" class="form-control" name="harga" value="{{ $barangs->harga }}" >
@if ($errors->has('harga'))
<span class="help-block">
<strong>{{ $errors->first('harga') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('deskripsi') ? ' has-error' : '' }}">
<label for="title" class="col-md-4 control-label">Deskripsi</label>
<div class="col-md-6">
<input type="text" class="form-control" name="deskripsi" value="{{ $barangs->deskripsi }}" >
@if ($errors->has('deskripsi'))
<span class="help-block">
<strong>{{ $errors->first('deskripsi') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('kategori') ? ' has-error' : '' }}">
<label for="title" class="col-md-4 control-label" value="{{ $barangs->gambar }}">Kategori</label>
<div class="col-md-6">
<select name="kategori" class="form-control">
<option value="makanan">Makanan</option>
<option value="minuman">Minuman</option>
<option value="alat tulis">Alat Tulis</option>
<option value="alat mandi">Alat Mandi</option>
</select>
@if ($errors->has('kategori'))
<span class="help-block">
<strong>{{ $errors->first('kategori') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('gambar') ? ' has-error' : '' }}">
<label for="title" class="col-md-4 control-label">Gambar</label>
<div class="col-md-6">
<input type="text" class="form-control" name="gambar" value="{{ $barangs->gambar }}" >
@if ($errors->has('gambar'))
<span class="help-block">
<strong>{{ $errors->first('gambar') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Simpan
</button>
</div>
</div>
</form>
</div>
</div>
</div>
@endsection
\ No newline at end of file
......@@ -9,14 +9,35 @@
@endsection
@section('main-content')
<div class="container-fluid spark-screen">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
</div>
</div>
</div>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>Nama Barang</th>
<th>Stock</th>
<th>Harga</th>
<th>Deskripsi</th>
<th>Kategori</th>
<th>Gambar</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach($barangs as $barang)
<tr>
<td>{{$barang->nama}}</td>
<td>{{$barang->jumlah}}</td>
<td>{{$barang->harga}}</td>
<td>{{$barang->deskripsi}}</td>
<td>{{$barang->kategori}}</td>
<td>{{$barang->gambar}}</td>
<td>
<a href="{{ url('/edit', $barang->id) }}" type="submit" button type="button" class="btn btn-warning">Edit</a>
<a href="{{ url('/delete', $barang->id) }}" class="btn btn-warning">Delete</a>
<!-- <a href="{{ url('/delete', $barang->id) }}" <onclick="return confirm('Yakin mau hapus data ini sob?')" class="btn btn-warning">Delete</a> -->
</tr>
@endforeach
</tbody>
</table>
<a href="{{ url('/create') }}" button type="button" class="btn btn-info">Create</a></button>
@endsection
......@@ -58,15 +58,12 @@ Route::group(['middleware' => ['web','auth','customer']], function () {
});
Route::group(['middleware' => ['web','auth','inventori']], function () {
Route::get('/ListBarang', 'InventoriController@ListBarang');
Route::get('/ListRequest', 'InventoriController@ListRequest');
// Route::get('/pegawai', 'OrderController@index');
// Route::get('/create', 'OrderController@create');
// Route::post('/store', 'OrderController@store');
// Route::get('/edit/{id}', 'OrderController@edit');
// Route::post('/update/{id}', 'OrderController@update');
// Route::get('/delete/{id}', 'OrderController@destroy');
// Route::get('/allTransaksi', 'TransaksiController@allTransaksi');
Route::get('/ListBarang', 'InventoriController@listBarang');
Route::get('/create', 'InventoriController@create');
Route::post('/store', 'InventoriController@store');
Route::get('/edit/{id}', 'InventoriController@edit');
Route::post('/update/{id}', 'InventoriController@update');
Route::get('/delete/{id}', 'InventoriController@destroy');
});
Route::group(['middleware' => ['web','auth','kasir']], function () {
......
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