📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Laravel Framework Laravel Helpers and Macros

Laravel Helpers and Macros

4 min read
Use Str::, Arr::, route(), config(), now() helpers and extend core classes with macros.

Laravel Helpers

// String helpers
Str::slug("Hello World");      // hello-world
Str::camel("hello_world");     // helloWorld
Str::studly("hello_world");    // HelloWorld
Str::snake("helloWorld");      // hello_world
Str::plural("child");          // children
Str::limit("Long text...", 20);// "Long text..."
Str::contains("Hello", "ell"); // true
Str::uuid();                   // UUID v4
Str::random(32);               // random string

// Array helpers
Arr::get($array, "user.name", "default");
Arr::set($array, "user.role", "admin");
Arr::has($array, "user.email");
Arr::pluck($users, "name");
Arr::first($items, fn($i) => $i > 5);

// Other helpers
route("posts.show", $post);
url("/path");
asset("css/app.css");
config("app.name");
env("APP_DEBUG", false);
now();           // Carbon instance
today();
dd($variable);   // dump and die
dump($variable); // dump and continue