Character list

1.1. Create a resource controller

Create a resource controller PHP artisan make: Controller Admin/RoleController -r or PHP artisan make:controller Admin/RoleController –resource

You can see that methods are generated for us by default. Then modify our inheritance of control:

1.2. Create resource routes

// Resource routing role management
Route::resource('role'.'RoleController');
Copy the code

We enterphp artisan route:listYou can view the route list:You can see the route aliasnameIt doesn’t fit the way we wrote it. We modify:Input againphp artisan route:listTo view the route list:And you can see that it fits the way we wrote it. We changed it directly in the routing group:Input againphp artisan route:listTo view the route list:And you can see it fits the way we wrote it. Finally, all codes of the current route are given:


      
// Background routing
// Route grouping
Route::group(['prefix'= >'admin'.'namespace'= >'Admin'].function () {
    // Login display
    Route::get('login'.'LoginController@index')->name('admin.login');
    // Login processing
    Route::post('login'.'LoginController@login')->name('admin.login');

    // The background requires validation to pass
    Route::group(['middleware'= > ['chadmin'].'as'= >'admin.'].function () {
        // The background page is displayed
        Route::get('index'.'IndexController@index')->name('index');

        // Welcome interface routing
        Route::get('welcome'.'IndexController@welcome')->name('welcome');

        / / exit
        Route::get('logout'.'IndexController@logout')->name('logout');

        // User management
        // List of users
        Route::get('user/index'.'UserController@index')->name('user.index');

        // The user add page displays the route
        Route::get('user/add'.'UserController@add')->name('user.add');

        // Add a user
        Route::post('user/add'.'UserController@create')->name('user.add');

        // Delete the user
        Route::get('user/del/{id}'.'UserController@del')->name('user.del');

        // Delete restore
        Route::get('user/restore/{id}'.'UserController@restore')->name('user.restore');

        // Select delete all
        Route::delete('user/delall'.'UserController@delall')->name('user.delall');

        // Send an email
        Route::get('user/email'.function () {
            \Mail::raw('Test one send mail'.function (\Illuminate\Mail\Message $message) {
                // Get the parameters in the callback method
                dump(func_get_args());

                / / who to send
                $message->to('[email protected]'.'Justin');

                / / theme
                $message->subject('Test mail');
            });
        }) -> name('email');

        // Modify the user display
        Route::get('user/edit/{id}'.'UserController@edit') -> name('user.edit');

        // Modify user processing
        Route::put('user/edit/{id}'.'UserController@update') -> name('user.edit');

        // Resource routing role management
        Route::resource('role'.'RoleController');
    });
});
Copy the code

1.3. Create a template

We can just take itresources\views\admin\userMake a copy and rename itroleTo modify:

Modify template code:resources\views\admin\index\index.blade.php:


Resources \ views \ admin \ role \ index blade. PHP:

<! DOCTYPE HTML> <html> <head> <meta charset="utf-8">
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="Width = device - width, initial - scale = 1, minimum - scale = 1.0, the maximum - scale = 1.0, user - scalable = no" />
	<link rel="stylesheet" type="text/css" href="/admin/static/h-ui/css/H-ui.min.css" />
	<link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/H-ui.admin.css" />
	<link rel="stylesheet" type="text/css" href="/ admin/lib/Hui - iconfont / 1.0.8 / iconfont. CSS" />
	<link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/skin/default/skin.css" id="skin" />
	<link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/style.css" />
	<link rel="stylesheet" href="{{asset('css/app.css')}}">
	<style>
		a {
			color: #fff;} < / style > < title > role management < / title > < / head > < body > < navclass="breadcrumb"> <i class="Hui-iconfont"> & #xe67f; </i> home page <span class="c-gray en"> &gt; </span> User center <span class="c-gray en"> &gt; </span> Role management <a class="btn btn-success radius r" style="line-height: 1.6em;margin-top: 3px" href="javascript:location.replace(location.href);" title= "refresh" > <i class="Hui-iconfont"> & #xe68f; </i></a></nav> <! -- Message prompt --> @include('admin.common.msg')

	<div class="page-container">
		<form method="get" class="text-c"> < span style = "max-width: 100%;input type="text" class="input-text" style="width: 250px" placeholder=" Enter role name"id= ""name="kw" autocomplete="off">
			<button type="submit" class="btn btn-success radius" id= ""name= "" > <i class="Hui-iconfont"> & #xe665; </i> Search for roles </button>
		</form>
		<div class="cl pd- 5bg- 1bk-gray mt- 20 "> <span class="l">
				<a href="{{route('admin.role.create')}}" class="btn btn-primary radius"> <! -- onclick="member_add('Add user'.'member-add.html'.' '.'510')" --> Hui-iconfont"> < a>  r"> < span style = "max-width: 100%; clear: both;$data->total()!!}</strong> 条</span>
		</div>
		<div class="mt-20"> table table-border table-bordered table-hover table-bg table-sort">  text-c"> 80">ID 100">  40< span style =" max-width: 100%; clear: both; min-height: 1em;130< span style =" max-width: 100%; clear: both; min-height: 1em;100</th> </tr> </thead> <tbody> @foreach($data as $item)
					<tr class="text-c">
						<td>{{$item -> id}}</td>
						<td>{{$item -> name}}</td>
						<td>
							<span class="label label-success radius"> # "> < / a >
							</span>
						</td>
						<td>{{$item -> created_at}}</td>
						<td class="td-manage">
							<span class="label label-primary radius">
								<a href="{{route('admin.role.edit'.$item)}}label label-danger radius"> {{route('admin.role.destroy'['id'= >$item -> id])}}"> delete < / a > < / span > < / td > < / tr > @ endforeach < / tbody > < / table > <! -- paging --> {{$data-> links() }} </div> </div> <! --_footer separated as a public template --> <script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"> text/javascript" src="/admin/lib/layer/2.4/layer.js"> text/javascript" src="/admin/static/h-ui/js/H-ui.min.js"> text/javascript" src="/admin/static/h-ui.admin/js/H-ui.admin.js"></script> <! --/_footer separated as a public template --> <! <script type="text/javascript" src="/admin/lib/My97DatePicker/4.8/WdatePicker.js"> text/javascript" src="/admin/lib/datatables/1.10.15/jquery.dataTables.min.js"> text/javascript" src="/admin/lib/laypage/1.2/laypage.js"> text/javascript"> function member_del(obj, id) {layer.confirm(' do I want to delete? ', function(index) { $.ajax({ type: 'POST', url: '', dataType: 'json', success: function(data) { $(obj).parents("tr").remove(); Layer. MSG (' Deleted! ', { icon: 1, time: 1000 }); }, error: function(data) { console.log(data.msg); }}); }); }   Copy the code

1.4. Add data

throughnavicatAdd two pieces of data:

Effect of 1.5,

If you find this article helpful on your way to learning PHP, please follow me to like and comment on it. Thank you, your blog is definitely another support for me to write.