php Laravel CRUD路由惯例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Laravel CRUD路由惯例相关的知识,希望对你有一定的参考价值。

<?php

// If we can represent a resource as for example, posts then the routing convention for its crud operations are as follows :



Route::get('/posts', 'PostsController@index'); //it will show all the posts using iteration

Route::get('/posts/create', 'PostsController@create');  //it will show a form to post to database

Route::post('/posts', 'PostsController@store'); //this will call a put request to posts route to store the form to DB

Route::get('/posts/{id}/edit', 'PostsController@edit') //this will show a form to edit/update a post

Route::patch('/posts/{id}', '@PostsController@update') //this will submit a PUT/PATCH request for updating a post

Route::get('/posts/{id}', 'PostsController@show') //To show a particular post

Route::delete('/posts/{id}', 'PostsController@destroy') //to Delete a specific post by spoofing a delete request from view


//To generate a resourceful controller with prefilled crud functions :
//php artisan make:controller PostsController -r



以上是关于php Laravel CRUD路由惯例的主要内容,如果未能解决你的问题,请参考以下文章

php 简单的CRUD laravel

laravel rbac的用户 角色 权限的crud

如何使用 vue axios 在 laravel 中解决 401 未授权响应

Laravel展示产品-CRUD之show

Laravel 路由参数和表单参数

LARAVEL - 使用 Route::resource 生成路由时无法使用销毁路由