Откроем контроллер
\app\Http\Controllers\Admin\TagController.php
public function
store(Request $request)
{
return $request->all();
}
{
return $request->all();
}
Откроем вид
\resources\views\admin\tag\tag.blade.php
<form role="form"
action="{{ route('tag.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">Tag title</label>
<input type="text" class="form-control"
id="name" name="name" placeholder="Tag
Title">
</div>
<div class="form-group">
<label for="slug">Tag Slug</label>
<input type="text" class="form-control"
id="slug" name="slug" placeholder="Post
Slug">
</div>
<div class="form-group">
<button type="submit" class="btn
btn-primary">Submit</button>
</div>
</div>
</div>
<!--
/.box-body -->
</form>
Идем по
адресу: http://blog.my/admin/tag/create
Заполняем
и отправляем форму. Получаем:
_token "bTnIXrOrhECGf5XNiomgucZqpJBiireoni6vZ3cD"
name "r"
slug "r"
Сделаем
валидацию полей. Откроем контроллер
\app\Http\Controllers\Admin\TagController.php
<?php
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Model\user\tag;
class TagController extends Controller
{
public function index()
{
return view('admin.tag.show');
}
public function create()
{
return view('admin.tag.tag');
}
public function store(Request $request)
{
$this->validate($request, [
'name' => 'required',
'slug' => 'required',
]);
$tag = new tag;
$tag->name = $request->name;
$tag->slug = $request->slug;
$tag->save();
return redirect(route('tag.index'));
}
public function show($id)
{
//
}
public function edit($id)
{
//
}
public function update(Request $request, $id)
{
//
}
public function destroy($id)
{
//
}
}
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Model\user\tag;
class TagController extends Controller
{
public function index()
{
return view('admin.tag.show');
}
public function create()
{
return view('admin.tag.tag');
}
public function store(Request $request)
{
$this->validate($request, [
'name' => 'required',
'slug' => 'required',
]);
$tag = new tag;
$tag->name = $request->name;
$tag->slug = $request->slug;
$tag->save();
return redirect(route('tag.index'));
}
public function show($id)
{
//
}
public function edit($id)
{
//
}
public function update(Request $request, $id)
{
//
}
public function destroy($id)
{
//
}
}
Идем в шаблон категории:
\resources\views\admin\category\category.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">Titles</h3>
</div>
<!--
/.box-header -->
<!--
form start -->
<form
role="form" action="{{ route('category.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">Category title</label>
<input type="text" class="form-control"
id="name" name="name" placeholder="Tag
Title">
</div>
<div class="form-group">
<label for="slug">Category Slug</label>
<input type="text" class="form-control"
id="slug" name="slug" placeholder="Post
Slug">
</div>
<div class="form-group">
<button type="submit" class="btn
btn-primary">Submit</button>
</div>
</div>
</div>
</form>
<!--
/.box -->
</div>
<!--
/.col-->
</div>
<!--
./row -->
</section>
<!--
/.content -->
</div>
<!--
/.content-wrapper -->
@endsection
Откроем
контроллер
\app\Http\Controllers\Admin\CategoryController.php
<?php
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;use App\Model\user\category;
class CategoryController extends Controller
{
public function index()
{
return view('admin.category.show');
}
public function create()
{
return view('admin.category.category');
}
public function store(Request $request)
{
$this->validate($request, [
'name' => 'required',
'slug' => 'required',
]);
$category = new category;
$category->name = $request->name;
$category->slug = $request->slug;
$category->save();
return redirect(route('category.index'));
}
public function show($id)
{
//
}
public function edit($id)
{
//
}
public function update(Request $request, $id)
{
//
}
public function destroy($id)
{
//
}
}
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;use App\Model\user\category;
class CategoryController extends Controller
{
public function index()
{
return view('admin.category.show');
}
public function create()
{
return view('admin.category.category');
}
public function store(Request $request)
{
$this->validate($request, [
'name' => 'required',
'slug' => 'required',
]);
$category = new category;
$category->name = $request->name;
$category->slug = $request->slug;
$category->save();
return redirect(route('category.index'));
}
public function show($id)
{
//
}
public function edit($id)
{
//
}
public function update(Request $request, $id)
{
//
}
public function destroy($id)
{
//
}
}
Скопируем в шаблоны
category.blade.php и tag.blade.php
сообщения об ошибках.
@if
(count($errors) > 0)
@foreach ($errors->all() as $error)
<p class="alert alert-danger">{{ $error }}</p>
@endforeach
@endif
Создадим в шаблоне
файл об ошибках валидации:
\resources\views\includes\messages.blade.php
Теперь во все шаблоны
мы вставляем эту строку:
@include('includes.messages')
Копируем из файла
таблицы:
file:///W:/domains/blog.my/Row%20files/admin/pages/tables/data.html
и вставляем в файл
\resources\views\admin\tag\show.blade.php
Откроем
адрес: http://blog.my/admin/tag
\resources\views\admin\layouts\head.blade.php
в конце
файла пишем:
@section('headSection')
@show
\resources\views\admin\layouts\footer.blade.php
в конце
файла пишем:
@section('footerSection')
@show
Страница будет
выглядеть так: \resources\views\admin\tag\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">Title</h3>
<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">
<h3
class="box-title">Data Table With Full Features</h3>
</div>
<!--
/.box-header -->
<div
class="box-body">
<table id="example1" class="table table-bordered
table-striped">
<thead>
<tr>
<th>S.No</th>
<th>Tag Name</th>
<th>Slug</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr>
<td>Trident</td>
<td>Internet
Explorer 4.0
</td>
<td>Win 95+</td>
<td> 4</td>
<td>X</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>S.No</th>
<th>Tag Name</th>
<th>Slug</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()
$('#example2').DataTable({
'paging'
: true,
'lengthChange': false,
'searching' : false,
'ordering' : true,
'info'
: true,
'autoWidth' : false
})
})
</script>
@endsection
Выведем
записи из БД.
\app\Http\Controllers\Admin\TagController.php
public function
index()
{
$tags = tag::all();
return view('admin.tag.show', compact('tags'));
}
{
$tags = tag::all();
return view('admin.tag.show', compact('tags'));
}
Идем на страницу
шаблона: \resources\views\admin\tag\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">Tags</h3>
<a
class="col-lg-offset-5 btn btn-success" href="{{
route('tag.create') }}">Add New Tag</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">
<h3
class="box-title">Data Table With Full Features</h3>
</div>
<!--
/.box-header -->
<div
class="box-body">
<table id="example1" class="table table-bordered
table-striped">
<thead>
<tr>
<th>S.No</th>
<th>Tag Name</th>
<th>Slug</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
@foreach ($tags as $tag)
<tr>
<td>{{
$loop->index + 1 }}</td>
<td>{{
$tag->name }}</td>
<td>{{
$tag->slug }}</td>
<td>Edit</td>
<td>Delete</td>
</tr>
@endforeach
</tbody>
<tfoot>
<tr>
<th>S.No</th>
<th>Tag Name</th>
<th>Slug</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()
$('#example2').DataTable({
'paging'
: true,
'lengthChange': false,
'searching' : false,
'ordering' : true,
'info'
: true,
'autoWidth' : false
})
})
</script>
@endsection
Идем на страницу
шаблона: \resources\views\admin\tag\tag.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">Titles</h3>
</div>
<!--
/.box-header -->
@include('includes.messages')
<!--
form start -->
<form
role="form" action="{{ route('tag.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">Tag title</label>
<input type="text" class="form-control"
id="name" name="name" placeholder="Tag
Title">
</div>
<div class="form-group">
<label for="slug">Tag Slug</label>
<input type="text" class="form-control"
id="slug" name="slug" placeholder="Post
Slug">
</div>
<div class="form-group">
<button type="submit" class="btn
btn-primary">Submit</button>
<a type="button" href="{{
route('tag.index') }}" class="btn btn-warning">Back</a>
</div>
</div>
</div>
<!--
/.box-body -->
</form>
<!--
/.box -->
</div>
<!--
/.col-->
</div>
<!--
./row -->
</section>
<!--
/.content -->
</div>
<!--
/.content-wrapper -->
@endsection
Идем на страницу
шаблона: \resources\views\admin\category\category.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">Categories</h3>
</div>
<!--
/.box-header -->
@include('includes.messages')
<!--
form start -->
<form
role="form" action="{{ route('category.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">Category title</label>
<input type="text" class="form-control"
id="name" name="name" placeholder="Tag
Title">
</div>
<div class="form-group">
<label for="slug">Category Slug</label>
<input type="text" class="form-control"
id="slug" name="slug" placeholder="Post
Slug">
</div>
<div class="form-group">
<button type="submit" class="btn
btn-primary">Submit</button>
<a type="button" href="{{
route('category.index') }}" class="btn
btn-warning">Back</a>
</div>
</div>
</div>
</form>
<!--
/.box -->
</div>
<!--
/.col-->
</div>
<!--
./row -->
</section>
<!--
/.content -->
</div>
<!--
/.content-wrapper -->
@endsection
Идем на страницу
шаблона: \resources\views\admin\category\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">Category create</h3>
<a
class="col-lg-offset-5 btn btn-success" href="{{
route('category.create') }}">Add New Category</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-body">
<table id="example1" class="table table-bordered
table-striped">
<thead>
<tr>
<th>S.No</th>
<th>Tag Name</th>
<th>Slug</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
@foreach ($categories as $category)
<tr>
<td>{{
$loop->index + 1 }}</td>
<td>{{
$category->name }}</td>
<td>{{
$category->slug }}</td>
<td>Edit</td>
<td>Delete</td>
</tr>
@endforeach
</tbody>
<tfoot>
<tr>
<th>S.No</th>
<th>Tag Name</th>
<th>Slug</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</tfoot>
</table>
</div>
</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
Выведем
записи из БД.
\app\Http\Controllers\Admin\CategoryController.php
public function
index()
{
$categories = category::all();
return view('admin.category.show', compact('categories'));
}
{
$categories = category::all();
return view('admin.category.show', compact('categories'));
}
Посты
\resources\views\admin\post\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">Posts</h3>
<a
class="col-lg-offset-5 btn btn-success" href="{{
route('post.create') }}">Add New Post</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-body">
<table id="example1" class="table table-bordered
table-striped">
<thead>
<tr>
<th>S.No</th>
<th>Title</th>
<th>Sub Title</th>
<th>Slug</th>
<th>Created at</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
@foreach ($posts as $post)
<tr>
<td>{{ $loop->index + 1 }}</td>
<td>{{ $post->title }}</td>
<td>{{ $post->subtitle }}</td>
<td>{{ $post->slug}}</td>
<td>{{ $post->created_at }}</td>
<td>Edit</td>
<td>Delete</td>
</tr>
@endforeach
</tbody>
<tfoot>
<tr>
<th>S.No</th>
<th>Title</th>
<th>Sub Title</th>
<th>Slug</th>
<th>Created at</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</tfoot>
</table>
</div>
</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
Посты
\resources\views\admin\post\post.blade.php
Контроллер
app\Http\Controllers\Admin\PostController.php
public function
index()
{
$posts = post::all();
return view('admin.post.show', compact('posts'));
}
{
$posts = post::all();
return view('admin.post.show', compact('posts'));
}
Комментариев нет:
Отправить комментарий