Разрешения для админа.
Откроем шаблон
\resources\views\admin\role\create.blade.php
@extends('admin.layouts.app')
@section('main-content')
<div
class="content-wrapper">
<!--
Content Header (Page header) -->
<section
class="content-header">
<h1>
Text
Editors
<small>Advanced form element</small>
</h1>
<ol
class="breadcrumb">
<li><a
href="#"><i class="fa fa-dashboard"></i>
Home</a></li>
<li><a
href="#">Forms</a></li>
<li
class="active">Editors</li>
</ol>
</section>
<!-- Main
content -->
<section
class="content">
<div
class="row">
<div
class="col-md-12">
<!--
general form elements -->
<div
class="box box-primary">
<div
class="box-header with-border">
<h3
class="box-title">Roles</h3>
</div>
<!--
/.box-header -->
@include('includes.messages')
<!--
form start -->
<form
role="form" action="{{ route('role.store') }}"
method="post">
{{
csrf_field() }}
<div
class="box-body">
<div class="col-lg-offset-3 col-lg-6">
<div class="form-group">
<label for="name">Role title</label>
<input type="text" class="form-control"
id="name" name="name" placeholder="Role
Title">
</div>
<div class="col-lg-6">
<label for="name">Posts Permissions</label>
<div class="checkbox">
<label><input type="checkbox"
/>Create</label>
</div>
<div class="checkbox">
<label><input type="checkbox"
/>Create</label>
</div>
<div class="checkbox">
<label><input type="checkbox"
/>Create</label>
</div>
<div class="checkbox">
<label><input type="checkbox"
/>Create</label>
</div>
</div>
<div class="col-lg-6">
<label for="name">User Permissions</label>
<div class="checkbox">
<label><input type="checkbox"
/>Create</label>
</div>
<div class="checkbox">
<label><input type="checkbox"
/>Create</label>
</div>
<div class="checkbox">
<label><input type="checkbox"
/>Create</label>
</div>
<div class="checkbox">
<label><input type="checkbox"
/>Create</label>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn
btn-primary">Submit</button>
<a type="button" href="{{ route('role.index')
}}" class="btn btn-warning">Back</a>
</div>
</div>
</div>
<!--
/.box-body -->
</form>
<!--
/.box -->
</div>
<!--
/.col-->
</div>
<!--
./row -->
</section>
<!--
/.content -->
</div>
<!--
/.content-wrapper -->
@endsection
Сделаем в разрешениях
еще текстовое поле
http://blog.my/admin/permission/create
Откроем миграции
\database\migrations\2017_09_10_200912_create_permissions_table.php
public function
up()
{
Schema::create('permissions', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('for');
$table->timestamps();
});
Schema::create('permissions_role', function (Blueprint $table) {
$table->integer('role_id');
$table->integer('permission_id');
});
}
{
Schema::create('permissions', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('for');
$table->timestamps();
});
Schema::create('permissions_role', function (Blueprint $table) {
$table->integer('role_id');
$table->integer('permission_id');
});
}
Идем в вид
\resources\views\admin\permission\create.blade.php
@extends('admin.layouts.app')
@section('main-content')
<div
class="content-wrapper">
<!--
Content Header (Page header) -->
<section
class="content-header">
<h1>
Text
Editors
<small>Advanced form element</small>
</h1>
<ol
class="breadcrumb">
<li><a
href="#"><i class="fa fa-dashboard"></i>
Home</a></li>
<li><a
href="#">Forms</a></li>
<li
class="active">Editors</li>
</ol>
</section>
<!-- Main
content -->
<section
class="content">
<div
class="row">
<div
class="col-md-12">
<!--
general form elements -->
<div
class="box box-primary">
<div
class="box-header with-border">
<h3
class="box-title">Permission</h3>
</div>
<!--
/.box-header -->
@include('includes.messages')
<!--
form start -->
<form
role="form" action="{{ route('permission.store') }}"
method="post">
{{
csrf_field() }}
<div
class="box-body">
<div class="col-lg-offset-3 col-lg-6">
<div class="form-group">
<label for="name">Permission title</label>
<input type="text" class="form-control"
id="name" name="name" placeholder="Permission
Title">
</div>
<div class="form-group">
<label
for="for">Permission for</label>
<select
name="for" id="for" class="form-control">
<option
selected disable>Selected Permission for</option>
<option
value="user">User</option>
<option
value="post">Post</option>
<option
value="other">Other</option>
</select>
</div>
<div class="form-group">
<button type="submit" class="btn
btn-primary">Submit</button>
<a type="button" href="{{
route('permission.index') }}" class="btn
btn-warning">Back</a>
</div>
</div>
</div>
<!--
/.box-body -->
</form>
<!--
/.box -->
</div>
<!--
/.col-->
</div>
<!--
./row -->
</section>
<!--
/.content -->
</div>
<!--
/.content-wrapper -->
@endsection
Идем в контроллер
\app\Http\Controllers\Admin\PermissionController.php
public function
store(Request $request)
{
$this->validate($request, [
'name' => 'required|max:50|unique:permissions',
'for' => 'required'
]);
$permission = new Permission;
$permission->name = $request->name;
$permission->for = $request->for;
$permission->save();
return redirect(route('permission.index'));
}
{
$this->validate($request, [
'name' => 'required|max:50|unique:permissions',
'for' => 'required'
]);
$permission = new Permission;
$permission->name = $request->name;
$permission->for = $request->for;
$permission->save();
return redirect(route('permission.index'));
}
public function
update(Request $request, Permission $permission)
{
$this->validate($request, [
'name' => 'required|max:50',
'for' => 'required'
]);
$permission = Permission::find($permission->id);
$permission->name = $request->name;
$permission->for = $request->for;
$permission->save();
return redirect(route('permission.index'))->with('message', 'Permission updated successfully');
}
{
$this->validate($request, [
'name' => 'required|max:50',
'for' => 'required'
]);
$permission = Permission::find($permission->id);
$permission->name = $request->name;
$permission->for = $request->for;
$permission->save();
return redirect(route('permission.index'))->with('message', 'Permission updated successfully');
}
Идем в вид
\resources\views\admin\permission\show.blade.php
@extends('admin.layouts.app')
@section('headSection')
<link
rel="stylesheet" href="{{
asset('admin/bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css')
}}" />
@endsection
@section('main-content')
<div
class="content-wrapper">
<!--
Content Header (Page header) -->
<section
class="content-header">
<h1>
Blank page
<small>it
all starts here</small>
</h1>
<ol
class="breadcrumb">
<li><a
href="#"><i class="fa fa-dashboard"></i>
Home</a></li>
<li><a
href="#">Examples</a></li>
<li
class="active">Blank page</li>
</ol>
</section>
<!-- Main
content -->
<section
class="content">
<!--
Default box -->
<div
class="box">
<div
class="box-header with-border">
<h3
class="box-title">Permissions</h3>
<a
class="col-lg-offset-5 btn btn-success" href="{{
route('permission.create') }}">Add New Permission</a>
<div
class="box-tools pull-right">
<button type="button" class="btn btn-box-tool"
data-widget="collapse" data-toggle="tooltip"
title="Collapse">
<i
class="fa fa-minus"></i></button>
<button type="button" class="btn btn-box-tool"
data-widget="remove" data-toggle="tooltip"
title="Remove">
<i
class="fa fa-times"></i></button>
</div>
</div>
<div
class="box-body">
<div
class="box">
<div
class="box-header">
@include('includes.messages')
</div>
<!--
/.box-header -->
<div
class="box-body">
<table id="example1" class="table table-bordered
table-striped">
<thead>
<tr>
<th>S.No</th>
<th>Permission Name</th>
<th>Permission For</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
@foreach ($permissions as $permission)
<tr>
<td>{{ $loop->index + 1 }}</td>
<td>{{ $permission->name }}</td>
<td>{{ $permission->for }}</td>
<td><a href="{{
route('permission.edit',$permission->id) }}"><span
class="glyphicon glyphicon-edit"></span></a></td>
<td>
<form id="delete-form-{{ $permission->id }}"
method="post" action="{{ route('permission.destroy',
$permission->id) }}" style="display:none">
{{ csrf_field() }}
{{ method_field('DELETE') }}
</form>
<a href="" onclick="if(confirm('Are you sure, you
want to delete this?'))
{event.preventDefault();
document.getElementById('delete-form-{{ $permission->id
}}').submit();
}else{
event.preventDefault();
}"><span class="glyphicon
glyphicon-trash"></span></a>
</td>
</tr>
@endforeach
</tbody>
<tfoot>
<tr>
<th>S.No</th>
<th>Permission Name</th>
<th>Permission For</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</tfoot>
</table>
</div>
<!--
/.box-body -->
</div>
<!--
/.box -->
</div>
<!--
/.box-body -->
<div
class="box-footer">
Footer
</div>
<!--
/.box-footer-->
</div>
<!--
/.box -->
</section>
<!--
/.content -->
</div>
<!--
/.content-wrapper -->
@endsection
@section('footerSection')
<script
src="{{
asset('admin/bower_components/datatables.net/js/jquery.dataTables.min.js')
}}"></script>
<script
src="{{
asset('admin/bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js')
}}"></script>
<script>
$(function
() {
$('#example1').DataTable()
})
</script>
@endsection
Откроем
страницу http://blog.my/admin/role/create
Нам нужны поля для
ролей.
Откроем вид
\resources\views\admin\role\create.blade.php
Откроем контроллер
ролей \app\Http\Controllers\Admin\RoleController.php
Не забываем подключить:
use
App\Model\admin\Permission;
public function
create()
{
$permissions = Permission::all();
return view('admin.role.create', compact('permissions'));
}
{
$permissions = Permission::all();
return view('admin.role.create', compact('permissions'));
}
Комментариев нет:
Отправить комментарий