Laravel entry-level add, delete, modify and check operations

									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
Insert picture description here
folders in the resources / views / directory. Just like the controller name, create views
Insert picture description here
in the folder and create them in the view. The routing
preparation is completed.
Inquire:
Insert picture description here

  1. The rendered view in laravel is reutn view ()
  2. The template variable assignment in laravel is with () needs to follow behind the rendering
  3. The method of querying the database in laravel is get ().
    Insert picture description here
    Do n’t forget to introduce the DB class. The
    Insert picture description here
    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
    Insert picture description here
    which is the content of the database
    Insert picture description here
    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
Insert picture description here
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
Insert picture description here
concession is to add the route
Insert picture description here
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
Insert picture description here
delete only need to pass the ID of the data.
Insert picture description here
Routing needs to be noted here, the need to bring the uploaded value to
Insert picture description here
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

修改:
	修改和增加是一样的,分为两部分,一部分是渲染表单,还有一部分是将表单的值传到控制器

Insert picture description here
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

Insert picture description here
The template variable assignment is required to display the original data.
When you finally submit the modification form, you must not forget to pass
Insert picture description here
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! ! !

Published 4 original articles · won 10 · views 181

Guess you like

Origin blog.csdn.net/DarKer_LB/article/details/105427627