array_dot()

The dot () function allows you to convert a multidimensional array to a one-dimensional array using dot notation.

$array = [
    'user'= > ['username'= >'something'].'app'= > ['creator'= > ['name'= >'someone'].'created'= >'today']].$dot_array = array_dot($array);
// [user.username] => something, [app.creator.name] => someone, [app.created] => todayCopy the code

array_get()

Function retrieves values from multidimensional arrays using dot notation.

$array = [
    'user'= > ['username'= >'something'].'app'= > ['creator'= > ['name'= >'someone'].'created'= >'today']].$name = array_get($array.'app.creator.name');
// someoneCopy the code

The array_get() function also accepts an optional third argument as the default if key does not exist.

$name = array_get($array.'app.created.name'.'anonymous');
// anonymousCopy the code

public_path()

Returns the fully qualified absolute path to the public directory in the Laravel application. You can also pass paths to files or directories in the public directory to get an absolute path to the resource. It will simply add public_path() to your arguments.

$public_path = public_path();
$path = public_path('js/app.js');Copy the code

Str::orderedUuid()

(1) The function first generates a timestamp UUID. This UUID can be stored in an index database column. These Uuid's are created based on timestamps, so they retain your content index;



(2) use it, in Laravel 5.6 could trigger Ramsey, Uuid, Exception, UnsatisfiedDependencyException. To resolve this issue, simply run the following command to use the Moontoast/Math package



Composer require laravel/passport = ~ 7.0

use Illuminate\Support\Str;
return (string) Str::orderByUuid()
// A timestamp first uuidCopy the code

str_plural()

Converts a string to a plural form. This function only supports English.

echo str_plural('bank');
// banks
echo str_plural('developer');
// developersCopy the code

route()

Generates the route URL for the specified route.

$url = route('login'); If the route accepts arguments, you can simply pass them to an array as the second argument.$url = route('products'['id'= > 1)); If you want to generate a relative URL instead of an absolute URL, you can pass itfalseAs the third parameter.$url = route('products'['id'= > 1),false);Copy the code

tap()

It takes two arguments: a value and a closure. The value will be passed to the closure, and the value will be returned. The closure return value is irrelevant.

$user = App\User::find(1);

return tap($user.function($user) {
    $user->update([
        'name'= >'Random']); }); /** * it does not return a Boolean value, but the User Model. If you don't have a transitive closure, you can use any method of the User Model. * The return value will always be the value regardless of the actual method returned. In the following example, it will return the User Model instead of a Boolean value. * The update method returns a Boolean value, but because tap is used, it returns the User Model. * /$user = App\User::find(1);

return tap($user)->update([
    'name'= >'SomeName'
]);Copy the code

dump()

A given variable is dumped, and multiple variables can be passed in simultaneously. This is very useful for debugging.

$dump($var1);
dump($var1.$var2.$var3);Copy the code

str_slug()

Generates a URL-friendly SLug for the given string. You can use this feature to create a slug for a post or product title.

$slug = str_slug('Helpers in Laravel'.The '-');
// helpers-in-laravelCopy the code

optional()

Take a parameter, and you can call the method of the parameter or access the property. If the object passed is NULL, the methods and properties return NULL, rather than causing an error or throwing an exception.

$user = User::find(1);
return optional($user)->name;Copy the code