This article brings you a summary of the useful functions of Laravel5.2 and laravel5.3 frameworks (with code). It has certain reference value. Friends in need can refer to it. , hope it helps you.
The new feature of laravel5.2, set throttle through middleware to control the number of accesses based on IP
Principle: Through the return Pass three response headers X-RateLimit-Limit, X-RateLimit-Remaining, and Retry-After to control the number of accesses.
X-RateLimit-Limit: The maximum number of requests allowed within the specified time
X-RateLimit-Remaining: The remaining number of requests within the specified time
Retry-After: The distance below The time to wait for retry requests (s)
Code implementation:
// 一分钟内同一个IP限制访问5次 Route::group(['prefix' => 'admin', 'middleware' => 'throttle:5'], function(){ Route::get('user', 'UserController@show'); });
php artisan make:auth
3, all()
laravel5.3 New features
laravel5 .2: DB::table('users')->get()
returns an array.
laravel5.3:DB::table('users')->get()
Returns a collection.
If we are using laravel5.3
, we can pass DB::table('users')->get()->all()
Returning an array, but returning a collection also has certain benefits. We can use some methods of the collection to return the collection. For example, to take out the first element in the collection, we can directly use the first()
method.
4, $loop
laravel5.3 new features$loop Properties:
index: Loop index starting from 1
remaining: How many entries are left in the loop
count: Total number of loop entries
first: Whether Is the first
last: whether it is the last
depth: loop level
parent: if the loop is located in another @foreach, return the parent loop reference
Get data: User::paginate($num)
Template: $users->links()
May need to be introduced in the template css file, css file path public/css/app.css, you can directly
The above is the entire content of this article For more laravel content, please pay attention to laravel framework introductory tutorial.
Related recommendations:
Summary of how to use the collection class in Laravel (code)
laravel framework model How to create and use model
The above is the detailed content of Summary of useful functions of Laravel5.2 and laravel5.3 frameworks (with code). For more information, please follow other related articles on the PHP Chinese website!