Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the laravel function

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to use the laravel function", the content of the explanation is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to use the laravel function" bar!

Laravel functions are: 1, array_add (), you can add a given key-value pair to the array; 2, array_collapse (), you can fold each array of the array into a single array; 3, array_dot (), you can convert a multi-dimensional array into an one-dimensional array; 4, array_except (), and so on.

The operating environment of this tutorial: windows7 system, Laravel6 version, DELL G3 computer.

Common functions of laravel

Array type function

1. Array_add function

If the given 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

Fold each array of an array into a single array

Array_collapse ($array)

3 、 array_divide

Function returns two arrays, one containing the key of the original array and the other containing the value of the original array

Array_divide ($array)

4 、 array_dot

The multidimensional array is flattened into an one-dimensional array, and the depth is represented by "dot" syntax.

Array_dot ($array)

5 、 array_except

Removes the given key-value pair from the array

Array_except ($array, array ('key'))

6 、 array_first

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

Array_first ($array, function ($key, $value) {}, $default)

7 、 array_flatten

Flatten a multidimensional array to one dimension

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

8 、 array_forget

Removes a given key-value pair from a deeply nested array in dot syntax

Array_forget ($array, 'foo'); array_forget ($array,' foo.bar')

9 、 array_get

Use "dot" syntax to retrieve the given value from a deeply nested array

Array_get ($array, 'foo',' default'); array_get ($array, 'foo.bar',' default')

10 、 array_has

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

Array_has ($array, 'products.desk')

11 、 array_only

Returns the given key-value pair from the array

Array_only ($array, array ('key'))

12 、 array_pluck

Pull a list of given key-value pairs from the array

Array_pluck ($array, 'key')

13 、 array_pull

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

Array_pull ($array, 'key')

14 、 array_set

Use "dot" syntax to write values in deeply nested arrays

Array_set ($array, 'key',' value'); array_set ($array, 'key.subkey',' value')

15 、 array_sort

Sort an array by a given closure result

Array_sort ($array, function () {})

16 、 array_sort_recursive

Use the sort function to sort the array recursively

Array_sort_recursive ()

17 、 array_where

Filter the array using the given closure

Array_where ()

18 、 head

Returns the first element of a given array

Head ($array)

19 、 last

Returns the last element of a given array

Last ($array)

Path function

1 、 app_path

Get the full path to the app folder

App_path ()

2 、 base_path

Get the full path to the project root directory

Base_path ()

3 、 config_path

Get the full path to the application configuration directory

Config_path ()

4 、 database_path

Get the full path to the application database directory

Database_path ()

5 、 elixir

Get the path of the Elixir file with the version number

Elixir ()

6 、 public_path

Get the full path to the public directory

Public_path ()

7 、 storage_path

Get the full path to the storage directory

Storage_path ()

String function

1 、 camel_case

Converts a given string to a hump naming

Camel_case ($value)

2 、 class_basename

Returns the name of a class that does not contain a namespace

Class_basename ($class); class_basename ($object)

3 、 e

Run htmlentities on a given string

E ('')

4 、 starts_with

Determine whether the beginning of the string is a given content

Starts_with ('Foo bar.',' Foo')

5 、 ends_with

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

Ends_with ('Foo bar.',' bar.')

6 、 snake_case

Converts a given string to a serpentine name

Snake_case ('fooBar')

7 、 str_limit

Limit the number of characters in a string

Str_limit ()

8 、 str_contains

Determine whether a given string contains the specified content

Str_contains ('Hello foo bar.',' foo')

9 、 str_finish

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

Str_finish ('foo/bar',' /')

10 、 str_is

Determine whether the given string matches the given format

Str_is ('foo*',' foobar')

11 、 str_plural

Convert a string into a plural

Str_plural ('car')

12 、 str_random

Generate a random string of a given length

Str_random (25)

13 、 str_singular

Converts a string to a singular. This function currently supports only English

Str_singular ('cars')

14 、 str_slug

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

Str_slug ("Laravel 5 Framework", "-")

15 、 studly_case

Converts a given string to "uppercase naming": FooBar

Studly_case ('foo_bar')

16 、 trans

Translate the given sentence according to your localization file

Trans ('foo.bar')

17 、 trans_choice

Translate the given statement according to the suffix change

Trans_choice ('foo.bar', $count)

URLs and Links function

1 、 action

Generate a given controller behavior URL

Action ('FooController@method', $parameters)

2 、 asset

Generate resource file URLs based on the currently requested agreement (HTTP or HTTPS)

Asset ('img/photo.jpg', $title, $attributes)

3 、 secure_asset

Generate resource file URL according to HTTPS

Secure_asset ('img/photo.jpg', $title, $attributes)

4 、 route

Generate a given route name URL

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

5 、 url

Generate the full URL of the given path

Url ('path', $parameters = array (), $secure = null)

Miscellaneous function

1. Auth ()-> user ()

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

Auth ()-> user ()

2 、 back

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

Back ()

3 、 bcrypt

Use the value given by the Bcrypt hash. You can use it instead of Hash facade

Bcrypt ('my-secret-password')

4 、 collect

Generate a collection instance from a given project

Collect (['taylor',' abigail'])

5 、 config

Get the setting value of the setting option

Config ('app.timezone', $default)

6 、

Generate HTML form hidden fields that contain CSRF token content

{!! Csrf_field ()!!}

7 、 csrf_token

Get the contents of the current CSRF token

$token = csrf_token ()

8 、 dd

Output the given variable and end the script

Dd ($value)

9 、 env

Get the value of the environment variable or return the default value

$env = env ('APP_ENV'); $env = env (' APP_ENV', 'production')

10 、

Deliver a given event to the listener to which it belongs

Event (new UserRegistered ($user))

11 、

Generate a model factory builder based on a given class, name, and total

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

12 、

Generate HTML form hidden fields for the action content of the proposed HTTP form

{!! Method_field ('delete')!!}

13 、 old

Get the old input value from flash to session

$value = old ('value'); $value = old (' value', 'default')

14 、 redirect

Return to the redirector instance for redirection

Return redirect ('/ home')

15 、 request

Get the current request instance or input project

$value = request ('key', $default = null)

16 、 response

Create a response instance or get a response factory instance

Return response ('Hello World', 200, $headers)

17 、 session

Can be used to get or set a single session content

$value = session ('key')

18 、

When no parameters are passed, the session instance is returned

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

19 、

Returns a given value

Value (function () {return 'bar';})

20 、 view

Get a view instance

Return view ('auth.login')

21 、

Returns the given value

$value = with (new Foo)-> work (); thank you for reading, the above is the content of "how to use the laravel function", after the study of this article, I believe you have a deeper understanding of how to use the laravel function, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report