Helper Functions
So basically, you can not use string and array helpers in laravel 6. laravel 6 removed helpers function. You can use Illuminate\Support\Str and Illuminate\Support\Arr classes for helpers. so you can use all helpers function
Solution 1:
File name : index.php
Route::get('/', function () {
$newSlug = Str::slug('I am from itechxpert.in');
dd($newSlug);
});
Solution 2:
you want to use helpers functions then you need to install new composer package with following command:
File name : index.php
composer require laravel/helpers
Route::get('/', function () {
$newSlug = str_slug('I am from itechxpert.in');
dd($newSlug);
});
You can use Helpers like this way:
Arr::add
Arr::collapse
Arr::divide
Arr::dot
Arr::except
Arr::first
Arr::flatten
Arr::forget
Arr::get
Arr::has
Arr::last
Arr::only
Arr::pluck
Arr::prepend
Arr::pull
Arr::random
Arr::set
Arr::sort
Arr::sortRecursive
Arr::where
Arr::wrap
Str::after
Str::before
Str::camel
Str::contains
Str::containsAll
Str::endsWith
Str::finish
Str::is
Str::kebab
Str::limit
Str::orderedUuid
Str::plural
Str::random
Str::replaceArray
Str::replaceFirst
Str::replaceLast
Str::singular
Str::slug
Str::snake
Str::start
Str::startsWith
Str::studly
Str::title
Str::uuid
Str::words
How to get keys name from array using array helper
$myArray = [
'name'=>'Nusrat Bano',
'email'=>'itechxpert@gmail.com',
'website'=>'itechxpert.com'
];
$myArrayKey = array_keys($myArray);
dd($myArrayKey);
How to Get Logged in User Data
Get Logged User Data using helper
you can get login user details using auth() helper, it will return object of users details.
File name : index.php
$user = auth()->user();
print_r($user);
Get Logged User ID using helper
File name : index.php
$id = auth()->user()->id;
print_r($id);
Get Logged User Data using facade
File name : index.php
$user = Auth::user();
print_r($user);
Get Logged User ID using facade
File name : index.php
$id = Auth::user()->id;
print_r($id);
Previous
Next