我希望在laravel中为每条记录显示带有编辑和删除按钮的表格中的数据。
我必须在现有页面中显示它。
管理员控制器
<?php
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Category;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Auth;
class AdminController extends Controller
{
public function show()
{
return view('admin/admin');
}
public function addCategory()
{
$category=new Category;
$category->category_name = Input::get('category');
$category->save();
return view('admin/admin');
}
}
我的分类模型
命名空间App;
使用Illuminate \ Database \ Eloquent \ Model;
class Category extends Model
{
protected $table = "category";
protected $fillable = [
'category_name',
];
}
admin.blade.php
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
.bod{
background-color:#f8f8f8 ;
border-shadow: 5px 10px 20px white inset;
border-width:5px;
margin-top:-12px;
}
.h1{
font-family:"Book Antiqua";
font-size: 90px;
color: red;
text-align: center;
}
div {
border-radius: 5px;
/*background-color: #f2f2f2;*/
/*background-color: #7CA8C1 ;*/
padding: 20px;
position: relative;
border:2px solid white;
height: 200px;
width: 50%;
margin-left: 50px;
}
.txt{
width: 150px;
height:25px;
border: 2px solid white;
}
.btn{
width: 100px;
height:28px;
font-weight: bold;
border: 2px solid white;
}
</style>
</head>
<body class="bod">
<h1 class="h1">Admin</h1>
<div align="left">
<form action="{{ route('addCategory') }}" method="get">
{{ csrf_field() }}
<label for="category" style="font-family: 'Book Antiqua';font-size: 48px;color: #9999FF;">Category</label> <br/>
<table class="table ">
<tr>
<td align="center"><input class="txt" type="text" name="category" id="category" placeholder="Enter the Category" ></td>
<td align="center"></td>
<td align="center"> <input type="submit" name="add" id="add" value="ADD" class="btn"></td>
</tr>
</table>
</form>
</div>
</body>
</html>
我想在管理页面中显示管理员添加的所有类别以及更新和删除按钮我该如何实现?
答案 0 :(得分:1)
Address_type
和Student_type
是您的创建类型。
您忘了创建一个表Student_tbl
来携带您的插入数据。
您可以参考此演示
create type Address_type as object (
hno char(4),
street varchar2(10),
city varchar2(10)
);
create type Student_type as object (
sno char(4),
sname varchar2(10),
adddress Address_type
);
CREATE TABLE Student_tbl(
V1 Student_type
);
insert into Student_tbl values (Student_type('4567',
'Shan',
Address_type('30','aaa','bbb')
)
);
修改强>
如果您希望获得类似Address_type
的客户类型,您可能会这样做。
select t.SNO,
t.SNAME,
t.adddress.hno,
t.adddress.street,
t.adddress.city
from Student_tbl t