Struktur Folder Permission di dalam View
- Assign
- create.blade.php
@extends('layouts.master')
@section('title', 'Assign Permission')
@section('styles')
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
@endsection
@push('scripts')
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<script>
$(document).ready(function() {
$('.select2').select2({
placeholder: "Select Permissions"
});
});
</script>
@endpush
@section('content')
@if(session('success'))
<div class="col-lg-12">
<div class="alert alert-success alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-check"></i> Alert!</h4>
{{ session('success') }}
</div>
</div>
@endif
<div class="container-fluid">
<section class="content">
<div class="col-lg-12">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title"><b>Assign Permission</b></h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<form class="form-horizontal" method="POST" action="{{ route ('assign.create') }}">
@csrf
<div class="box-body">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<select name="role" id="role" class="form-control">
<option value="" disable selected>Choose a Role</option>
@foreach($roles as $role)
<option value="{{$role->id}}">{{$role->name}}</option>
@endforeach
</select>
@error('role')
<div class="text-danger mt-2 d-block">{{$message}}</div>
@enderror
</div>
</div>
<div class="form-group">
<label for="guard_name" class="col-sm-2 control-label">Permission</label>
<div class="col-sm-10">
<select name="permissions[]" id="permissions" class="form-control select2" multiple>
@foreach($permissions as $permission)
<option value="{{$permission->id}}">{{$permission->name}}</option>
@endforeach
</select>
@error('permissions')
<div class="text-danger mt-2 d-block">{{$message}}</div>
@enderror
</div>
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<button type="submit" class="btn btn-primary btn-flat btn-block pull-right">Save</button>
</div>
<!-- /.box-footer -->
</form>
</div>
</div>
</section>
<section class="content">
<div class="col-lg-12">
<div class="box box-primary">
<!-- /.box-header -->
<div class="box-body no-padding">
<table class="table">
<tbody>
<tr>
<th>#</th>
<th>Name</th>
<th>Guard Name</th>
<th>The Permissions</th>
<th>Action</th>
</tr>
@foreach($roles as $index=> $role)
<tr>
<td>{{$index + 1}}</td>
<td>{{$role->name}}</td>
<td>{{$role->guard_name}}</td>
<td>{{ implode(', ', $role->getPermissionNames()->toArray())}}</td>
<td class="text-center">
<a href="{{ route('assign.edit', $role) }}" class="btn btn-info btn-xs"><i class=" fa fa-edit (alias)"></i> Sync</a>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<!-- /.box-body -->
</div>
</div>
</section>
</div>
@endsection
- sync.blade.php
@extends('layouts.master')
@section('styles')
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
@endsection
@push('scripts')
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<script>
$(document).ready(function() {
$('.select2').select2({
placeholder: "Select Permissions"
});
});
</script>
@endpush
@section('content')
@if(session('success'))
<div class="col-lg-12">
<div class="alert alert-success alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-check"></i> Alert!</h4>
{{ session('success') }}
</div>
</div>
@endif
<div class="container">
<section class="content">
<div class="col-lg-12">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title"><b>Assign Permission</b></h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<form class="form-horizontal" method="POST" action="{{ route ('assign.edit', $role) }}">
@csrf
@method('PUT')
<div class="box-body">
<div class="form-group">
<label for="role" class="col-sm-2 control-label">Role</label>
<div class="col-sm-10">
<select name="role" id="role" class="form-control">
<option value="" disable selected>Choose a Role</option>
@foreach($roles as $item)
<option {{ $role->id == $item->id ? 'selected' : ''}} value="{{$item->id}}">{{$item->name}}</option>
@endforeach
</select>
@error('role')
<div class="text-danger mt-2 d-block">{{$message}}</div>
@enderror
</div>
</div>
<div class="form-group">
<label for="permission" class="col-sm-2 control-label">Permission</label>
<div class="col-sm-10">
<select name="permissions[]" id="permissions" class="form-control select2" multiple>
@foreach($permissions as $permission)
<option {{$role->permissions()->find($permission->id) ? "selected" : "" }} value="{{$permission->id}}">{{$permission->name}}</option>
@endforeach
</select>
</div>
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<a href="{{route('assign.create')}}" class="btn btn-warning btn-flat">Cancel</a>
<button type="submit" class="btn btn-primary btn-flat">Sync</button>
</div>
<!-- /.box-footer -->
</form>
</div>
</div>
</section>
</div>
@endsection
- User
- create.blade.php
@extends('layouts.master')
@section('styles')
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
@endsection
@push('scripts')
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<script>
$(document).ready(function() {
$('.select2').select2({
placeholder: "Select Permissions"
});
});
</script>
@endpush
@section('content')
@if(session('success'))
<div class="col-lg-12">
<div class="box box-default">
<div class="box-body">
<div class="alert alert-success alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-check"></i> Alert!</h4>
{{ session('success') }}
</div>
</div>
</div>
</div>
@endif
<div class="container-fluid">
<section class="content">
<div class="col-lg-12">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title"><b>Pick user by email address</b></h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<form class="form-horizontal" method="POST" action="{{ route ('assign.user.create') }}">
@csrf
<div class="box-body">
<div class="form-group">
<label for="user" class="col-sm-2 control-label">User</label>
<div class="col-sm-10">
<input type="email" name="email" id="email" class="form-control">
@error('role')
<div class="text-danger mt-2 d-block">{{$message}}</div>
@enderror
</div>
</div>
<div class="form-group">
<label for="roles" class="col-sm-2 control-label">Pick Roles</label>
<div class="col-sm-10">
<select name="roles[]" id="roles" class="form-control select2" multiple>
@foreach($roles as $role)
<option value="{{$role->id}}">{{$role->name}}</option>
@endforeach
</select>
@error('roles')
<div class="text-danger mt-2 d-block">{{$message}}</div>
@enderror
</div>
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<button type="submit" class="btn btn-primary btn-flat btn-block pull-right">Assign</button>
</div>
<!-- /.box-footer -->
</form>
</div>
</div>
</section>
<section class="content">
<div class="col-lg-12">
<div class="box box-primary">
<!-- /.box-header -->
<div class="box-body">
<table id="datatable" class="table table-bordered table-striped">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>The Role</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
@foreach($users as $index=> $user)
<tr>
<td>{{$index + 1}}</td>
<td>{{$user->name}}</td>
<td>{{ implode(', ', $user->getRoleNames()->toArray())}}</td>
<td class="text-center">
<form action="{{route ('assign.user.destroy', $user)}}" method="POST">
@csrf
@method('DELETE')
<a href="{{ route('assign.user.edit', $user) }}" class="btn btn-info btn-xs"><i class=" fa fa-edit (alias)"></i> Sync</a>
<button class="btn btn-danger btn-xs" onClick="return confirm('Yakin mau di hapus?')"><i class=" fa fa-times"></i> Hapus
</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<!-- /.box-body -->
</div>
</div>
</section>
</div>
@endsection
- edit.blade.php
@extends('layouts.master')
@section('styles')
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
@endsection
@push('scripts')
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<script>
$(document).ready(function() {
$('.select2').select2({
placeholder: "Select Permissions"
});
});
</script>
@endpush
@section('content')
@if(session('success'))
<div class="col-lg-12">
<div class="box box-default">
<div class="box-body">
<div class="alert alert-success alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-check"></i> Alert!</h4>
{{ session('success') }}
</div>
</div>
</div>
</div>
@endif
<div class="container-fluid">
<section class="content">
<div class="col-lg-12">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title"><b>Pick user by email address</b></h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<form class="form-horizontal" method="POST" action="{{ route ('assign.user.edit', $user) }}">
@csrf
@method('PUT')
<div class="box-body">
<div class="form-group">
<label for="user" class="col-sm-2 control-label">User</label>
<div class="col-sm-10">
<input type="email" name="email" id="email" class="form-control" value="{{$user->email}}">
@error('role')
<div class="text-danger mt-2 d-block">{{$message}}</div>
@enderror
</div>
</div>
<div class="form-group">
<label for="roles" class="col-sm-2 control-label">Pick Roles</label>
<div class="col-sm-10">
<select name="roles[]" id="roles" class="form-control select2" multiple>
@foreach($roles as $role)
<option {{$user->roles()->find($role->id) ? 'selected' : ''}} value="{{$role->id}}">{{$role->name}}</option>
@endforeach
</select>
@error('roles')
<div class="text-danger mt-2 d-block">{{$message}}</div>
@enderror
</div>
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<button type="submit" class="btn btn-primary btn-flat btn-block pull-right">Sync</button>
</div>
<!-- /.box-footer -->
</form>
</div>
</div>
</section>
</div>
@endsection
- Permission
- index.blade.php
@extends('layouts.master') @section('title', 'Create Permission') @section('content') <div class="container-fluid"> <section class="content"> <div class="col-lg-12"> <div class="box box-primary"> <div class="box-header with-border"> <h3 class="box-title"><b>Create Permission</b></h3> </div> <!-- /.box-header --> <!-- form start --> <form class="form-horizontal" method="POST" action="{{route ('permission.create') }}"> @csrf <div class="box-body"> <div class="form-group"> <label for="name" class="col-sm-2 control-label">Name</label> <div class="col-sm-10"> <input type="text" name="name" id="name" class="form-control" value="{{ old('name') ?? $permission->name }}"> </div> </div> <div class="form-group"> <label for="guard_name" class="col-sm-2 control-label">Guard Name</label> <div class="col-sm-10"> <input type="text" name="guard_name" id="guard_name" class="form-control" value="{{ old('guard-name') ?? $permission->guard_name }}" placeholder='default to "web"'> </div> </div> </div> <!-- /.box-body --> <div class="box-footer"> <button type="submit" class="btn btn-primary btn-flat btn-block pull-right">Save</button> </div> <!-- /.box-footer --> </form> </div> </div> </section> <section class="content"> <div class="col-lg-12"> <div class="box box-primary"> <!-- /.box-header --> <div class="box-body no-padding"> <table id="datatable" class="table"> <tbody> <tr> <th style="width: 50px">#</th> <th>Name</th> <th>Guard Name</th> <th>Created At</th> <th class="text-center">Option</th> </tr> @foreach($permissions as $index => $permission) <tr> <td>{{$index + 1}}</td> <td>{{$permission->name}}</td> <td>{{$permission->guard_name}}</td> <td>{{$permission->created_at->format('d F Y')}}</td> <td class="text-center"> <form action="{{route ('permission.destroy', $permission)}}" method="POST"> @csrf @method('DELETE') <a href="{{route ('permission.edit', $permission)}}" class="btn btn-info btn-sm"><i class=" fa fa-edit (alias)"></i> Edit</a> <button class="btn btn-danger btn-sm" onClick="return confirm('Yakin mau di hapus?')"><i class=" fa fa-times"></i> Hapus </button> </form> </td> </tr> @endforeach </tbody> </table>
</div>
<!-- /.box-body --> </div> </div> </section> </div> @endsection
- edit.blade.php
@extends('layouts.master')
@section('title', 'Edit Permission')
@section('content')
<div class="container">
<section class="content">
<div class="col-lg-12">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title"><b>Edit Permission</b></h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<form class="form-horizontal" method="POST" action="{{route ('permission.edit', $permission) }}">
@csrf
@method('PUT')
<div class="box-body">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" name="name" id="name" class="form-control" value="{{ old('name') ?? $permission->name }}">
</div>
</div>
<div class="form-group">
<label for="guard_name" class="col-sm-2 control-label">Guard Name</label>
<div class="col-sm-10">
<input type="text" name="guard_name" id="guard_name" class="form-control" value="{{ old('guard-name') ?? $permission->guard_name }}" placeholder='default to "web"'>
</div>
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<a href="{{route('permission.index')}}" class="btn btn-warning btn-flat">Cancel</a>
<button type="submit" class="btn btn-primary btn-flat">Update</button>
</div>
<!-- /.box-footer -->
</form>
</div>
</div>
</section>
</div>
@endsection
- Roles
- index.blade.php
@extends('layouts.master')
@section('title', 'Create Role')
@section('content')
<div class="container-fluid">
<section class="content">
<div class="col-lg-12">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title"><b>Create Roles</b></h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<form class="form-horizontal" method="POST" action="{{route ('roles.create') }}">
@csrf
<div class="box-body">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" name="name" id="name" class="form-control" value="{{ old('name') ?? $role->name }}">
</div>
</div>
<div class="form-group">
<label for="guard_name" class="col-sm-2 control-label">Guard Name</label>
<div class="col-sm-10">
<input type="text" name="guard_name" id="guard_name" class="form-control" value="{{ old('guard-name') ?? $role->guard_name }}" placeholder='default to "web"'>
</div>
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<button type="submit" class="btn btn-primary btn-flat btn-block pull-right">Save</button>
</div>
<!-- /.box-footer -->
</form>
</div>
</div>
</section>
<section class="content">
<div class="col-lg-12">
<div class="box box-primary">
<!-- /.box-header -->
<div class="box-body no-padding">
<table id="datatable" class="table">
<tbody>
<tr>
<th style="width: 50px">#</th>
<th>Name</th>
<th>Guard Name</th>
<th>Created At</th>
<th class="text-center">Option</th>
</tr>
@foreach($roles as $index => $role)
<tr>
<td>{{$index + 1}}</td>
<td>{{$role->name}}</td>
<td>{{$role->guard_name}}</td>
<td>{{$role->created_at->format('d F Y')}}</td>
<td class="text-center">
<form action="{{route ('roles.destroy', $role)}}" method="POST">
@csrf
@method('DELETE')
<a href="{{route ('roles.edit', $role)}}" class="btn btn-info btn-sm"><i class=" fa fa-edit (alias)"></i> Edit</a>
<button class="btn btn-danger btn-sm" onClick="return confirm('Yakin mau di hapus?')"><i class=" fa fa-times"></i> Hapus
</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<!-- /.box-body -->
</div>
</div>
</section>
</div>
@endsection
- edit.blade.php
@extends('layouts.master')
@section('content')
<div class="container-fluid">
<section class="content">
<div class="col-lg-12">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title"><b>Update Roles</b></h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<form class="form-horizontal" method="POST" action="{{route ('roles.edit', $role) }}">
@csrf
@method('PUT')
<div class="box-body">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" name="name" id="name" class="form-control" value="{{ old('name') ?? $role->name }}">
</div>
</div>
<div class="form-group">
<label for="guard_name" class="col-sm-2 control-label">Guard Name</label>
<div class="col-sm-10">
<input type="text" name="guard_name" id="guard_name" class="form-control" value="{{ old('guard-name') ?? $role->guard_name }}" placeholder='default to "web"'>
</div>
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<a href="{{route('roles.index')}}" class="btn btn-warning btn-flat">Cancel</a>
<button type="submit" class="btn btn-primary btn-flat">Update</button>
</div>
<!-- /.box-footer -->
</form>
</div>
</div>
</section>
</div>
@endsection
Post a Comment