Home> PHP Framework> Laravel> body text

[laravel] blog project practical notes - operations of creating a project and logging in

演明
Release: 2021-09-06 10:38:23
Original
1203 people have browsed it

I always want to do a small project by myself, but I don’t know how to start. I always do a certain part of the project when I go to work, and I don’t do a project as a whole. The following is a summary of the videos I watched on the PHP Chinese website. Notes for your reference. This is a practical blog project done in a Windows environment.

1. Create the project

1) Switch to the project directory (I put all the projects in the code folder)

cd code
Copy after login

2) Create Project (the project name is blog)

composer create-project laravel/laravel blog --prefer-dist 指优先安装压缩版
Copy after login

2. Distribute routing and verification code references

1) First assign a route (each reference address must be assigned Routing)

After the creation is successful, check whether it can be successfully accessed

2) Reference the third-party library (under the resource folder, represented by org)

3) In the controller Load classrequire_once '../resources/org/code/Code.class.php';

session_start();The laravel framework itself encapsulates the session. It is possible to use the native session when referencing the extension class. The entry file index.php enables the call of the

require_once '../resources/org/code/Code.class.php'; //先把类包含进来,实际路径根据实际情况进行修改。 $code = new Code(); //实例化一个对象 $code->doimg(); $_SESSION['code'] = $code->getCode();//验证码保存到SESSION中
Copy after login

image: use the routing access method

{{url('') }}

It is possible that the verification code is not clear:

This is when we add a click event to create a new verification code every time we clickalt="' onclick=" this.src='{{'home/code'}}'"

Some browsers will think that the address has not changed, so the verification code remains unchanged

alt="' onclick="this.src='{{'home/code'}}?'-Math.random()"
Copy after login

3. Login form submission CRFS authentication and verification code judgment

1) Note that when submitting the form, the submit button must be in

2) 419 error is laravel In the CRFS authentication question of the framework, write {{csrf_field()}} in the

3) The name in the input tag is the value to be passed to the background

4) Use Input:: all() takes the value passed from the front desk, which is equivalent to is_post. Use back to return to the previous page with the information stored in the session

   if($input = Input::all()){   $code = new \Code; //实例化一个对象    $_code = $code->getCode(); //获取本身的验证码   if($input['code'] != $_code ){      return back()-> with('msg','验证码错误!');    }else{      dd(123);    }   }else{   return view('home/login');   }
Copy after login

5) Use the session to determine the value of the page prompt information

 @if(session('msg'))    

{{session('msg')}}

@endif
Copy after login

The above steps are my study notes. I wrote down the steps or key points to be operated. If you don’t understand anything, you can leave a message. Thank you for your support. I hope it can help newcomers. If you want to see more blog project information, Follow me and continue sharing in the next article.

Recommended learning: "laravel tutorial"

The above is the detailed content of [laravel] blog project practical notes - operations of creating a project and logging in. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!