laravel入门级增删改查操作
Routes, controllers, views
Add , delete, and modify checks need to understand the above, you can see my previous blog to
add a link description
First of all, you need to create controllers, routes, and views. Create controllers
in the app / http / Controllers / directory. Create
folders in the resources / views / directory. Just like the controller name, create views
in the folder and create them in the view. The routing
preparation is completed.
Inquire:
- The rendered view in laravel is reutn view ()
- The template variable assignment in laravel is with () needs to follow behind the rendering
- The method of querying the database in laravel is get ().
Do n’t forget to introduce the DB class. The
next step is to output the content of the query database to the front end.
The data has been passed through the template variable assignment just now, and it only needs to be looped
. 1. use php tags need laravel in front of a plus! Finally, of course do not forget to write the end of the
data circulating in the view cycle is written like this {{$ alias -> field}}
look at the effect of it
which is the content of the database
this Is what we queried
Add:
Unlike the query, we need to render the form form first, and then use the form to add
Just use retutn view () to render and OK.
We will directly add the
action of the form form. I will not explain it in the
end. The last csrf is very important. Laravel comes with it to protect the form. If it is not added, the form is useless The
concession is to add the route
1 to use the request to receive the form pass value
2 insert the database operation in laravel is insert
Delete:
delete does not need to use the form to pass the value, but the route to pass the value to
delete only need to pass the ID of the data.
Routing needs to be noted here, the need to bring the uploaded value to
delete should be the easiest in the addition, deletion and modification check
Yes , the most important thing is to successfully pass the data id to the controller. The delete operation is delete in laravel
修改:
修改和增加是一样的,分为两部分,一部分是渲染表单,还有一部分是将表单的值传到控制器
The difference between modification and addition is that the modification needs to know the id of the data, so the id needs to be passed in when rendering the form
The template variable assignment is required to display the original data.
When you finally submit the modification form, you must not forget to pass
the id. The modification is almost the same as the increase. The most important thing is this id. Because the modification requires conditions, the id must not be lost.
This is the entry-level addition, deletion and modification of laravel. I hope my article can help everyone, thank you! ! !