Summary of useful functions of Laravel5.2 and laravel5.3 frameworks (with code)

01-28-2024

What this article brings to you is a functional summary of Laravel5.2 and laravel5.3 frameworks (with code attached), which has certain reference value. Friends who need it can refer to it and hope to help you. 1. The new feature of controlling access times laravel5.2, which controls access times according to IP by setting throttle through middleware.

Principle: Control the access times by returning three response headers X-RateLimit-Limit, X-RateLimit-Remaining and Retry-After.

X-RateLimit-Limit: the maximum number of requests allowed in a specified time.

X-RateLimit-Remaining: the number of requests remaining in the specified time.

Retry-After: the time to wait until the next retry request (s)

Code implementation:

//Access is restricted to the same IP for 5 times in one minute. Route::group(['prefix' => 'admin', 'middleware' => 'throttle:5'], function(){ Route::get('user', 'UserController@show'); });

2. A magical command to realize login and registration. The new feature of laravel5.2 is php artisan make:auth.

3、all()

Laravel5.3 new features

Laravel 5.2: db:: table ('users')-> get () returns an array. Laravel 5.3: db:: table ('users')-> get () returns a collection.

If we are using laravel5.3, we can return the array through DB::table('users')->get()->all (), but there are some advantages to returning the collection. We can use some methods of returning the collection, such as taking out the first element in the collection and using the first () method directly.

4、$loop

Laravel5.3' s new feature $loop variable is an attribute provided by $loop in the @foreach loop:

Index: circular index starting from 1.

Remaining: How many entries are left in the loop?

Count: the total number of entries in the loop.

First: Is it the first one?

Last: Is it the last one?

Depth: cycle level

Parent: If the loop is in another @foreach, return the parent loop reference.

5. Ultra-simple paging data retrieval: user:: page ($ NUM) template: $users->links ()

A css file may need to be introduced into the template. The css file path is public/css/app.css, which can be directly used.

Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us