Home> PHP Framework> Laravel> body text

What are laravel functions

青灯夜游
Release: 2022-04-28 12:22:11
Original
3181 people have browsed it

Laravel functions include: 1. array_add(), which can add a given key-value pair to an array; 2. array_collapse(), which can collapse each array of the array into a single array; 3. array_dot (), which can convert a multi-dimensional array into a one-dimensional array; 4. array_except(), etc.

What are laravel functions

The operating environment of this tutorial: Windows 7 system, Laravel 6 version, DELL G3 computer.

laravel common functions

Array type function

1, array_add function

If the given The key does not exist in the array. The array_add function adds the given key-value pair to the array.

array_add($array, 'key', 'value');
Copy after login

2. array_collapse

Collapses each array of the array into a single array

array_collapse($array);
Copy after login

3. array_divide

The function returns two arrays, one containing the keys of the original array and the other containing the values of the original array

array_divide($array);
Copy after login

4. array_dot

Flatten the multi-dimensional array into a one-dimensional array, and use "dot" syntax to express the depth

array_dot($array);
Copy after login

5, array_except

Remove the given key-value pair from the array

array_except($array, array('key'));
Copy after login

6, array_first

Return the first element in the array that passes the true test

array_first($array, function($key, $value){}, $default);
Copy after login

7, array_flatten

Flatten the multi-dimensional array into one dimension

['Joe', 'PHP', 'Ruby']; array_flatten(['name' => 'Joe', 'languages' => ['PHP', 'Ruby']]);
Copy after login

8, array_forget

Use "dot" syntax to remove a given key-value pair from a deeply nested array

array_forget($array, 'foo'); array_forget($array, 'foo.bar');
Copy after login

9, array_get

Use "Dot" syntax retrieves a given value from a deeply nested array

array_get($array, 'foo', 'default'); array_get($array, 'foo.bar', 'default');
Copy after login

10. array_has

Use "dot" syntax to check whether a given item exists in the array

array_has($array, 'products.desk');
Copy after login

11, array_only

Return the given key-value pair from the array

array_only($array, array('key'));
Copy after login

12, array_pluck

Pull out a given key-value pair from the array

array_pluck($array, 'key');
Copy after login

13, array_pull

Removes and returns the given key-value pair from the array

array_pull($array, 'key');
Copy after login

14, array_set

Use "dot" syntax Write a value in a deeply nested array

array_set($array, 'key', 'value'); array_set($array, 'key.subkey', 'value');
Copy after login

15, array_sort

Sort the array by the result of the given closure

array_sort($array, function(){});
Copy after login

16, array_sort_recursive

Use the sort function to recursively sort the array

array_sort_recursive();
Copy after login

17, array_where

Use the given closure to filter the array

array_where();
Copy after login

18, head

Return the given array The first element

head($array);
Copy after login

19, last

Returns the last element of the given array

last($array);
Copy after login

Path function

1. app_path

Get the full path of the app folder

app_path();
Copy after login

2. base_path

Get the full path of the project root directory

base_path();
Copy after login

3.config_path

Get the full path of the application configuration directory

config_path();
Copy after login

4. database_path

Get the full path of the application database directory

database_path();
Copy after login

5.elixir

Get the Elixir file path plus the version number

elixir();
Copy after login

6, public_path

Get the full path of the public directory

public_path();
Copy after login

7, storage_path

Get storage The full path of the directory

storage_path();
Copy after login

String function

1, camel_case

Convert the given string into camel case naming

camel_case($value);
Copy after login

2. class_basename

Returns the class name without namespace

class_basename($class); class_basename($object);
Copy after login

3. e

Run htmlentities on the given string

e('');
Copy after login

4 , starts_with

Determine whether the beginning of the string is the given content

starts_with('Foo bar.', 'Foo');
Copy after login

5, ends_with

Determine whether the end of the given string is the specified content

ends_with('Foo bar.', 'bar.');
Copy after login

6. snake_case

Convert the given string into a snake name

snake_case('fooBar');
Copy after login

7. str_limit

Limit the number of characters in the string

str_limit();
Copy after login

8 , str_contains

Determine whether the given string contains the specified content

str_contains('Hello foo bar.', 'foo');
Copy after login

9, str_finish

Add the given content to the end of the string, foo/bar/

str_finish('foo/bar', '/');
Copy after login

10. str_is

Determine whether the given string matches the given format

str_is('foo*', 'foobar');
Copy after login

11. str_plural

Convert the string into plural form

str_plural('car');
Copy after login

12, str_random

Generate a random string of a given length

str_random(25);
Copy after login

13, str_singular

Convert the string into singular form. This function currently only supports English

str_singular('cars');
Copy after login

14, str_slug

Generate a URL-friendly "slug" from a given string

str_slug("Laravel 5 Framework", "-");
Copy after login

15, studly_case

Convert the given string to "capitalization": FooBar

studly_case('foo_bar');
Copy after login

16, trans

Translate the given statement according to your localization file

trans('foo.bar');
Copy after login

17 , trans_choice

Translate the given statement according to the suffix change

trans_choice('foo.bar', $count);
Copy after login

URLs and Links function

1、action

generated to Define the controller behavior URL

action('FooController@method', $parameters);
Copy after login

2, asset

Generate the resource file URL based on the current request protocol (HTTP or HTTPS)

asset('img/photo.jpg', $title, $attributes);
Copy after login

3, secure_asset

Generate resource file URL according to HTTPS

secure_asset('img/photo.jpg', $title, $attributes);
Copy after login

4, route

Generate URL of given route name

route($route, $parameters, $absolute = true);
Copy after login

5, url

Generate URL of given path Full URL

url('path', $parameters = array(), $secure = null);
Copy after login

Miscellaneous function

1. auth()->user()

Returns an authenticator instance. You can use this instead of the Auth facade

auth()->user();
Copy after login

2, back

Generate a redirect response to return the user to the previous location

back();
Copy after login

3, bcrypt

Hash the given value using Bcrypt. You can use this instead of Hash facade

bcrypt('my-secret-password');
Copy after login

4, collect

Generate a collection instance from a given project

collect(['taylor', 'abigail']);
Copy after login

5, config

Get the setting value of the setting option

config('app.timezone', $default);
Copy after login

6、

产生包含 CSRF 令牌内容的 HTML 表单隐藏字段

{!! csrf_field() !!}
Copy after login

7、csrf_token

取得当前 CSRF 令牌的内容

$token = csrf_token();
Copy after login

8、dd

输出给定变量并结束脚本运行

dd($value);
Copy after login

9、env

取得环境变量值或返回默认值

$env = env('APP_ENV'); $env = env('APP_ENV', 'production');
Copy after login

10、

配送给定事件到所属的侦听器

event(new UserRegistered($user));
Copy after login

11、

根据给定类、名称以及总数产生模型工厂建构器

$user = factory(App\User::class)->make();
Copy after login

12、

产生拟造 HTTP 表单动作内容的 HTML 表单隐藏字段

{!! method_field('delete') !!}
Copy after login

13、old

取得快闪到 session 的旧有输入数值

$value = old('value'); $value = old('value', 'default');
Copy after login

14、redirect

返回重定向器实例以进行 重定向

return redirect('/home');
Copy after login

15、request

取得目前的请求实例或输入的项目

$value = request('key', $default = null)
Copy after login

16、response

创建一个回应实例或获取一个回应工厂实例

return response('Hello World', 200, $headers);
Copy after login

17、session

可被用于取得或设置单一 session 内容

$value = session('key');
Copy after login

18、

在没有传递参数时,将返回 session 实例

$value = session()->get('key'); session()->put('key', $value);
Copy after login

19、

返回给定数值

value(function(){ return 'bar'; });
Copy after login

20、view

取得视图 实例

return view('auth.login');
Copy after login

21、

返回给定的数值

$value = with(new Foo)->work();
Copy after login

【相关推荐:laravel视频教程

The above is the detailed content of What are laravel functions. 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!