Home  >  Article  >  PHP Framework  >  What are laravel functions

What are laravel functions

青灯夜游
青灯夜游Original
2022-04-28 12:22:113282browse

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');

2. array_collapse

Collapses each array of the array into a single array

array_collapse($array);

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);

4. array_dot

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

array_dot($array);

5, array_except

Remove the given key-value pair from the array

array_except($array, array('key'));

6, array_first

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

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

7, array_flatten

Flatten the multi-dimensional array into one dimension

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

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');

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');

10. array_has

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

array_has($array, 'products.desk');

11, array_only

Return the given key-value pair from the array

array_only($array, array('key'));

12, array_pluck

Pull out a given key-value pair from the array

array_pluck($array, 'key');

13, array_pull

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

array_pull($array, 'key');

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');

15, array_sort

Sort the array by the result of the given closure

array_sort($array, function(){});

16, array_sort_recursive

Use the sort function to recursively sort the array

array_sort_recursive();

17, array_where

Use the given closure to filter the array

array_where();

18, head

Return the given array The first element

head($array);

19, last

Returns the last element of the given array

last($array);

Path function

1. app_path

Get the full path of the app folder

app_path();

2. base_path

Get the full path of the project root directory

base_path();

3.config_path

Get the full path of the application configuration directory

config_path();

4. database_path

Get the full path of the application database directory

database_path();

5.elixir

Get the Elixir file path plus the version number

elixir();

6, public_path

Get the full path of the public directory

public_path();

7, storage_path

Get storage The full path of the directory

storage_path();

String function

1, camel_case

Convert the given string into camel case naming

camel_case($value);

2. class_basename

Returns the class name without namespace

class_basename($class);
class_basename($object);

3. e

Run htmlentities on the given string

e(&#39;<html>&#39;);

4 , starts_with

Determine whether the beginning of the string is the given content

starts_with(&#39;Foo bar.&#39;, &#39;Foo&#39;);

5, ends_with

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

ends_with(&#39;Foo bar.&#39;, &#39;bar.&#39;);

6. snake_case

Convert the given string into a snake name

snake_case(&#39;fooBar&#39;);

7. str_limit

Limit the number of characters in the string

str_limit();

8 , str_contains

Determine whether the given string contains the specified content

str_contains(&#39;Hello foo bar.&#39;, &#39;foo&#39;);

9, str_finish

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

str_finish(&#39;foo/bar&#39;, &#39;/&#39;);

10. str_is

Determine whether the given string matches the given format

str_is(&#39;foo*&#39;, &#39;foobar&#39;);

11. str_plural

Convert the string into plural form

str_plural(&#39;car&#39;);

12, str_random

Generate a random string of a given length

str_random(25);

13, str_singular

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

str_singular(&#39;cars&#39;);

14, str_slug

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

str_slug("Laravel 5 Framework", "-");

15, studly_case

Convert the given string to "capitalization": FooBar

studly_case(&#39;foo_bar&#39;);

16, trans

Translate the given statement according to your localization file

trans(&#39;foo.bar&#39;);

17 , trans_choice

Translate the given statement according to the suffix change

trans_choice(&#39;foo.bar&#39;, $count);

URLs and Links function

1、action

generated to Define the controller behavior URL

action(&#39;FooController@method&#39;, $parameters);

2, asset

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

asset(&#39;img/photo.jpg&#39;, $title, $attributes);

3, secure_asset

Generate resource file URL according to HTTPS

secure_asset(&#39;img/photo.jpg&#39;, $title, $attributes);

4, route

Generate URL of given route name

route($route, $parameters, $absolute = true);

5, url

Generate URL of given path Full URL

url(&#39;path&#39;, $parameters = array(), $secure = null);

Miscellaneous function

1. auth()->user()

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

auth()->user();

2, back

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

back();

3, bcrypt

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

bcrypt(&#39;my-secret-password&#39;);

4, collect

Generate a collection instance from a given project

collect([&#39;taylor&#39;, &#39;abigail&#39;]);

5, config

Get the setting value of the setting option

config(&#39;app.timezone&#39;, $default);

6、

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

 {!! csrf_field() !!}

7、csrf_token

取得当前 CSRF 令牌的内容

$token = csrf_token();

8、dd

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

dd($value);

9、env

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

$env = env(&#39;APP_ENV&#39;);
$env = env(&#39;APP_ENV&#39;, &#39;production&#39;);

10、

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

 event(new UserRegistered($user));

11、

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

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

12、

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

 {!! method_field(&#39;delete&#39;) !!}

13、old

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

$value = old(&#39;value&#39;);
$value = old(&#39;value&#39;, &#39;default&#39;);

14、redirect

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

return redirect(&#39;/home&#39;);

15、request

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

$value = request(&#39;key&#39;, $default = null)

16、response

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

 return response(&#39;Hello World&#39;, 200, $headers);

17、session

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

$value = session(&#39;key&#39;);

18、

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

$value = session()->get(&#39;key&#39;);
session()->put(&#39;key&#39;, $value);

19、

返回给定数值

value(function(){ return &#39;bar&#39;; });

20、view

取得视图 实例

 return view(&#39;auth.login&#39;);

21、

返回给定的数值

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

【相关推荐: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!

Statement:
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
Previous article:What are laravel cmsNext article:What are laravel cms