Commit c0d0728e by Aan Choesni Herlingga

master user

parent 4a247b2b
<?php
namespace App\Http\Controllers\Webprofile;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\UserRequest;
use App\Repositories\UserRepository;
use Crypt;
class UserController extends Controller
{
public function __construct(UserRepository $userRepo)
{
$this->userRepo = $userRepo;
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$users = $this->userRepo->get();
$data = [
'users' => $users,
];
return view('webprofile.backend.users.index', $data)->withTitle(trans('feature.user'));
}
public function status($id, Request $request)
{
$data = $request->except('_token');
$user = $this->userRepo->findId($id);
$this->userRepo->update($data, $user);
return redirect()->route('user.index');
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('webprofile.backend.users.create')->withTitle(trans('feature.create_user'));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\Response
*/
public function store(UserRequest $request)
{
$user = auth()->user();
$data = $request->except('_token');
$data['password'] = bcrypt($request->input('password'));
$data['is_active'] = 1;
$data['userid_created'] = $user->id;
$data['userid_updated'] = $user->id;
$this->userRepo->store($data);
return redirect()->route('user.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)
{
$id = Crypt::decrypt($id);
$user = $this->userRepo->findId($id);
$data = [
'user' => $user,
];
return view('webprofile.backend.users.edit', $data)->withTitle(trans('feature.edit_user'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
*
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$user = $this->userRepo->findId($id);
if ($request->input('password') != null || $request->input('password') != '') {
$data = $request->except('_token');
$data['password'] = bcrypt($request->password);
$this->userRepo->update($data, $user);
} else {
$data = $request->except('_token', 'password', 'password_confirmation');
$this->userRepo->update($data, $user);
}
return redirect()->route('user.index');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
*
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
}
}
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UserRequest 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 [
'name' => 'required',
'email' => 'required',
'password' => 'required|min:8',
'password_confirmation' => 'required|min:8|same:password',
];
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function messages()
{
return [
'required' => 'Form Input Ini Tidak Boleh Kosong / Harus Diisi',
'min' => 'Password minimal 8 karakter',
'password_confirmation.same' => 'Password tidak sama',
];
}
}
<?php
namespace App\Repositories;
use App\User;
class UserRepository extends Repository
{
protected $model;
public function __construct(User $model)
{
$this->model = $model;
}
public function get($with = null)
{
return $this->model
->when($with, function ($query) use ($with) {
return $query->with($with);
})
->orderBy('name', 'asc')
->get();
}
}
...@@ -2,13 +2,16 @@ ...@@ -2,13 +2,16 @@
namespace App; namespace App;
use App\Http\Traits\UuidTrait;
use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable class User extends Authenticatable
{ {
use Notifiable; use Notifiable, UuidTrait;
public $incrementing = false;
protected $keyType = 'string';
/** /**
* The attributes that are mass assignable. * The attributes that are mass assignable.
...@@ -16,7 +19,7 @@ class User extends Authenticatable ...@@ -16,7 +19,7 @@ class User extends Authenticatable
* @var array * @var array
*/ */
protected $fillable = [ protected $fillable = [
'name', 'email', 'password', 'name', 'email', 'password', 'role', 'is_active',
]; ];
/** /**
......
...@@ -28,4 +28,5 @@ return [ ...@@ -28,4 +28,5 @@ return [
'upload' => 'Upload', 'upload' => 'Upload',
'download' => 'Download', 'download' => 'Download',
'title_show' => 'Title Show', 'title_show' => 'Title Show',
'as' => 'Sebagai',
]; ];
...@@ -28,4 +28,5 @@ return [ ...@@ -28,4 +28,5 @@ return [
'upload' => 'Unggah', 'upload' => 'Unggah',
'download' => 'Unduh', 'download' => 'Unduh',
'title_show' => 'Judul ditampilkan', 'title_show' => 'Judul ditampilkan',
'as' => 'Sebagai',
]; ];
@extends('webprofile.backend.layouts.master')
@section('title')
{{ $title }}
@stop
@section('breadcrumbs')
<li><a href="{{ url('dashboard') }}">@lang('label.dashboard')</a></li>
<li class="active">@lang('feature.create_user')</li>
@stop
@section('content')
{!! Form::open(array('url' => route('user.store'), 'method' => 'POST', 'id' => 'user', 'class' => 'form-horizontal')) !!}
{!! csrf_field() !!}
<!-- page start-->
<div class="row">
<div class="col-md-9">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><strong>@lang('label.create')</strong> @lang('feature.user')</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<div class="form-group @if ($errors->has('role')) has-error @endif">
<label class="col-md-2 control-label">@lang('label.as')</label>
<div class="col-md-10">
{{ Form::select('role', ['admin'=>'Administrator', 'laman'=>'Pengelola Laman'], old('role'), array('class' => 'form-control')) }}
@if ($errors->has('role'))
<label id="login-error" class="error" for="login">{{$errors->first('role')}}</label>
@endif
</div>
</div>
<div class="form-group @if ($errors->has('name')) has-error @endif">
<label class="col-md-2 control-label">@lang('label.name')</label>
<div class="col-md-10">
{{ Form::text('name', old('name'), array('class' => 'form-control')) }}
@if ($errors->has('name'))
<label id="login-error" class="error" for="login">{{$errors->first('name')}}</label>
@endif
</div>
</div>
<div class="form-group @if ($errors->has('email')) has-error @endif">
<label class="col-md-2 control-label">Email</label>
<div class="col-md-10">
{{ Form::email('email', old('email'), array('class' => 'form-control')) }}
@if ($errors->has('email'))
<label id="login-error" class="error" for="login">{{$errors->first('email')}}</label>
@endif
</div>
</div>
<div class="form-group @if ($errors->has('password')) has-error @endif">
<label class="col-md-2 control-label">Password</label>
<div class="col-md-10">
{{ Form::password('password', array('class' => 'form-control')) }}
@if ($errors->has('password'))
<label id="login-error" class="error" for="login">{{$errors->first('password')}}</label>
@endif
</div>
</div>
<div class="form-group @if ($errors->has('password_confirmation')) has-error @endif">
<label class="col-md-2 control-label">Password</label>
<div class="col-md-10">
{{ Form::password('password_confirmation', array('class' => 'form-control')) }}
@if ($errors->has('password_confirmation'))
<label id="login-error" class="error" for="login">{{$errors->first('password_confirmation')}}</label>
@endif
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-9">
<div class="panel panel-default">
<div class="panel-footer">
<a href="{{ url('user') }}" class="btn btn-default pull-right">@lang('label.cancel')</a>
<button class="btn btn-info pull-right">@lang('label.save')</button>
</div>
</div>
</div>
</div>
{!! Form::close() !!}
<!-- page end-->
@stop
@section('script')
{!! Html::script('https://statik.unesa.ac.id/perpus_konten_statik/admin/js/plugins/bootstrap/bootstrap-datepicker.js') !!}
{!! Html::script('https://statik.unesa.ac.id/perpus_konten_statik/admin/js/plugins/bootstrap/bootstrap-timepicker.min.js') !!}
{!! Html::script('https://statik.unesa.ac.id/perpus_konten_statik/admin/js/plugins/bootstrap/bootstrap-file-input.js') !!}
{!! Html::script('https://statik.unesa.ac.id/perpus_konten_statik/admin/js/plugins/summernote/summernote.js') !!}
@stop
@extends('webprofile.backend.layouts.master')
@section('title')
{{ $title }}
@stop
@section('breadcrumbs')
<li><a href="{{ url('dashboard') }}">@lang('label.dashboard')</a></li>
<li class="active">@lang('feature.edit_user')</li>
@stop
@section('content')
{!! Form::model($user, ['route' => ['user.update', $user->id], 'method'=>'patch', 'class'=>'form-horizontal']) !!}
{!! csrf_field() !!}
<!-- page start-->
<div class="row">
<div class="col-md-9">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><strong>@lang('label.edit')</strong> @lang('feature.user')</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<div class="form-group @if ($errors->has('role')) has-error @endif">
<label class="col-md-2 control-label">@lang('label.as')</label>
<div class="col-md-10">
{{ Form::select('role', ['admin'=>'Administrator', 'laman'=>'Pengelola Laman'], old('role'), array('class' => 'form-control')) }}
@if ($errors->has('role'))
<label id="login-error" class="error" for="login">{{$errors->first('role')}}</label>
@endif
</div>
</div>
<div class="form-group @if ($errors->has('name')) has-error @endif">
<label class="col-md-2 control-label">@lang('label.name')</label>
<div class="col-md-10">
{{ Form::text('name', old('name'), array('class' => 'form-control')) }}
@if ($errors->has('name'))
<label id="login-error" class="error" for="login">{{$errors->first('name')}}</label>
@endif
</div>
</div>
<div class="form-group @if ($errors->has('email')) has-error @endif">
<label class="col-md-2 control-label">Email</label>
<div class="col-md-10">
{{ Form::email('email', old('email'), array('class' => 'form-control')) }}
@if ($errors->has('email'))
<label id="login-error" class="error" for="login">{{$errors->first('email')}}</label>
@endif
</div>
</div>
<div class="form-group @if ($errors->has('password')) has-error @endif">
<label class="col-md-2 control-label">Password</label>
<div class="col-md-10">
{{ Form::password('password', array('class' => 'form-control')) }}
@if ($errors->has('password'))
<label id="login-error" class="error" for="login">{{$errors->first('password')}}</label>
@endif
</div>
</div>
<div class="form-group @if ($errors->has('password_confirmation')) has-error @endif">
<label class="col-md-2 control-label">Password</label>
<div class="col-md-10">
{{ Form::password('password_confirmation', array('class' => 'form-control')) }}
@if ($errors->has('password_confirmation'))
<label id="login-error" class="error" for="login">{{$errors->first('password_confirmation')}}</label>
@endif
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-9">
<div class="panel panel-default">
<div class="panel-footer">
<a href="{{ url('user') }}" class="btn btn-default pull-right">@lang('label.cancel')</a>
<button class="btn btn-info pull-right">@lang('label.save')</button>
</div>
</div>
</div>
</div>
{!! Form::close() !!}
<!-- page end-->
@stop
@section('script')
{!! Html::script('https://statik.unesa.ac.id/perpus_konten_statik/admin/js/plugins/bootstrap/bootstrap-datepicker.js') !!}
{!! Html::script('https://statik.unesa.ac.id/perpus_konten_statik/admin/js/plugins/bootstrap/bootstrap-timepicker.min.js') !!}
{!! Html::script('https://statik.unesa.ac.id/perpus_konten_statik/admin/js/plugins/bootstrap/bootstrap-file-input.js') !!}
{!! Html::script('https://statik.unesa.ac.id/perpus_konten_statik/admin/js/plugins/summernote/summernote.js') !!}
@stop
@extends('webprofile.backend.layouts.master')
@section('title')
{{ $title }}
@stop
@section('breadcrumbs')
<li><a href="{{ url('dashboard') }}">@lang('label.dashboard')</a></li>
<li class="active">@lang('feature.user')</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/user/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 datatable table-hover" id="berita">
<thead>
<tr>
<th width="7%">@lang('label.number')</th>
<th width="20%">@lang('label.name')</th>
<th width="30%">Email</th>
<th width="18%">Role</th>
<th width="10%">Status</th>
<th align="center" width="15%">@lang('label.action')</th>
</tr>
</thead>
<tbody>
<?php $no = 1;?>
@foreach($users as $value)
<tr style="cursor:pointer">
<td align="center"><?php echo $no; ?></td>
<td>{!! $value->name !!}</td>
<td>{!! $value->email !!}</td>
<td>
@if($value->role == 'admin')
Administrator
@endif
@if($value->role == 'laman')
Pengelola Laman
@endif
</td>
<td style="text-align: center;">
@if($value->is_active == 1)
<i class="fa fa-check" style="color: green"></i>
@endif
@if($value->is_active == 0)
<i class="fa fa-times" style="color: red"></i>
@endif
</td>
<td style="text-align:center;">
@if($value->is_active == 0)
<button class="btn btn-success btn-xs" id="btn_status" data-file="{{$value->id}}"><i class="fa fa-check"></i></button>
{!! Form::model($value, ['route' => ['user.status', $value->id], 'method'=>'patch', 'id' => 'status_'.$value->id, 'style' => 'display: none;']) !!}
{!! Form::hidden('is_active', 1) !!}
{{ csrf_field() }}
{{ Form::close() }}
@endif
@if($value->is_active == 1)
<button class="btn btn-danger btn-xs" id="btn_status" data-file="{{$value->id}}"><i class="fa fa-times"></i></button>
{!! Form::model($value, ['route' => ['user.status', $value->id], 'method'=>'patch', 'id' => 'status_'.$value->id, 'style' => 'display: none;']) !!}
{!! Form::hidden('is_active', 0) !!}
{{ csrf_field() }}
{{ Form::close() }}
@endif
<a href="{{ route('user.edit', ['data'=>Crypt::encrypt($value->id)]) }}" class="btn btn-warning btn-xs"><i class="fa fa-pencil"></i></a>
<button class="btn btn-danger btn-xs" id="btn_delete" data-file="{{$value->id}}"><i class="fa fa-trash-o"></i></button>
{{ Form::open(['url'=>route('user.destroy', ['data'=>Crypt::encrypt($value->id)]), 'method'=>'delete', 'id' => $value->id, 'style' => 'display: none;']) }}
{{ csrf_field() }}
{{ Form::close() }}
</td>
<?php $no++;?>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
<!-- END DEFAULT DATATABLE -->
</div>
</div>
<!-- page end-->
@stop
@section('script')
{!! Html::script('https://statik.unesa.ac.id/perpus_konten_statik/admin/js/plugins/datatables/jquery.dataTables.min.js') !!}
<script>
$('button#btn_delete').on('click', function(e){
e.preventDefault();
var data = $(this).attr('data-file');
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("Terhapus","Data berhasil dihapus", "success");
setTimeout(function() {
$("#"+data).submit();
}, 1000); // 1 second delay
}
else{
swal("Dibatalkan","Data batal dihapus", "error");
}
}
);});
$('button#btn_status').on('click', function(e){
e.preventDefault();
var data = $(this).attr('data-file');
swal({
title : "Apakah Anda yakin?",
text : "Data ini dipakai!",
type : "warning",
showCancelButton : true,
confirmButtonColor: "#DD6B55",
confirmButtonText : "Yes",
cancelButtonText : "No",
closeOnConfirm : false,
closeOnCancel : false
},
function(isConfirm){
if(isConfirm){
swal("Dipakai","Data dipakai", "success");
setTimeout(function() {
$("#status_"+data).submit();
}, 1000); // 1 second delay
}
else{
swal("cancelled","Dibatalkan", "error");
}
}
);});
</script>
@stop
<?php <?php
Route::group(['middleware' => 'auth'], function () { Route::group(['middleware' => 'auth'], function () {
Route::group(['middleware' => 'role:admin'], function () {
Route::group(['namespace' => 'Webprofile', 'prefix' => 'webprofile'], function () {
Route::resource('user', 'UserController');
Route::patch('users_status/{id}', 'UserController@status')->name('user.status');
});
});
Route::group(['middleware' => 'role:admin|editor'], function () { Route::group(['middleware' => 'role:admin|editor'], function () {
Route::group(['namespace' => 'Webprofile\Backend', 'prefix' => 'webprofile'], function () { Route::group(['namespace' => 'Webprofile\Backend', 'prefix' => 'webprofile'], function () {
Route::resource('category', 'CategoryController'); Route::resource('category', 'CategoryController');
......
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