laravel resource风格
2024-08-29 20:34:22
resource 风格
概念
一种软件架构风格、设计风格,而不是标准,只是提供了一组设计原则和约束条件。它主要用于客户端和服务器交互类的软件。基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存等机制。
URL定义
资源:互联网所有的事物都可以被抽象为资源
资源操作:使用POST、DELETE、PUT、GET,使用不同方法对资源进行操作。
分别对应 添加、 删除、修改、查询
路由:
Route::prefix('api')->group(function ()
{
Route::resource('photo','PhotoController');
});
composer 安装资源路由控制器
php artisan make:controller PhotoController --resource
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; class PhotoController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
echo "index";
} /**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
echo "create";
} /**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
echo "store";
} /**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
echo 'show'.$id;
} /**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
echo 'edit'.$id;
} /**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
echo 'update'.$id;
} /**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
echo 'destroy'.$id;
}
}
最新文章
- RadioGroup实现导航栏
- paip.自动import的实现跟java.lang.SecurityException Prohibited package name java
- 【JAVA】";骗人";的“replaceAll”
- 《University Calculus》-chaper13-多重积分-三重积分的引入
- 省队集训day6 B
- MySQL取得当前时间的函数是什么 格式化日期的函数是什么
- mysql_config_editor程序的用法
- 在centos上部署java WEB环境
- [SCOI 2011]糖果
- 2015-11-06 ajax
- TestNG 单元测试框架的使用
- 利用Linux信号SIGUSR1调试程序
- Notepad++ 大小写转换
- Word Ladder 有必要深究。非图的广度优先遍历。标记
- HTML第二课——css
- js中两种定时器的设置及清除
- PHP中的递增/递减运算符
- asp中将系统货币符号¥改为美国货币符号$的做法
- #Spring实战第二章学习笔记————装配Bean
- STM32f103的电阻触摸屏的五点校正算法
热门文章
- HOOK API(二) —— HOOK自己程序的 MessageBox
- 【收藏】Supervisor的作用与配置
- 关于unix下cp命令复制权限不够的问题
- shell脚本命令(sotr/unip/tr/cut/eval)与正则表达式
- java 监听redis事件
- Pandas中Series与Dataframe的初始化
- Jest_JavaScript测试框架
- Solution -「HDU #6566」The Hanged Man
- 私有化轻量级持续集成部署方案--03-部署web服务(下)
- 带分数--第四届蓝桥杯省赛C++B/C组