PHP code example of darkghosthunter / larahelp
1. Go to this page and download the library: Download darkghosthunter/larahelp library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
darkghosthunter / larahelp example snippets
$result = app_call('\App\MyService\Service@createSomething');
class Something {
public function foo() {
return 'bar';
}
}
call_existing(new Something, 'bar'); // null
call_existing(new Something, 'foo'); // "bar"
public function store(Request $request): Response
{
// ...
return created([$post->getKeyName() => $post->getKey()];
}
$array = [
'foo' => [
'bar' => null
]
];
data_update($array, 'foo.bar', function ($value) {
if ($value === null) {
return 'baz';
}
})
// [
// 'foo' => [
// 'bar' => 'baz'
// ]
// ];
$array = [
'foo' => 'bar',
'baz' => 'qux',
'quux' => 'quuz',
]
[$baz, $quux] = delist($array, 1);
$seconds = diff('now', '15th may');
$minutes = diff('today', now())
$path = dot_path('files/user_id_312/videos/');
// files.user_id_312.videos
$enclosed = enclose('foo');
$enclosed();
// "foo"
$content = files()->get('text.txt');
trait Child {
// ..
}
trait Parent {
use Child;
// ..
}
class Foo {
use Parent;
}
has_trait(Foo::class, Child::class);
// true
$hash = hashy('This is a hashable string');
// "TJYa8+63dRbdN6w44shX1g=="
hashy('This is a hashable string', 'TJYa8+63dRbdN6w44shX1g==');
// true
hashy('This is a hashable string!', 'TJYa8+63dRbdN6w44shX1g==');
// false
if (in_console()) {
return "We're in console";
}
$result = in_console(fn() => 'foo');
// "foo"
if (in_development()) {
return "Do anything, it doesn't matter!";
}
$result = in_development(fn() => 'foo');
// "foo"
use App\Models\User;
$user = User::find(1);
$post = logged_in($user, function (User $user) {
return $user->post()->create([
// ..
]);
});
use Illuminate\Support\Collection;
$methods = methods_of(Collection::class)
return $methods->has('make');
// true
trait Parent {
// ..
}
class Foo {
use Parent;
}
missing_trait(Foo::class, Child::class);
// true
$subject = 'foo';
none_of('foo', ['bar', 'baz', 'qux']);
// false
$subject = 'foo';
none_of('foo', ['bar', 'baz', 'qux'], fn ($subject, $compared) => $subject === $compared);
// false
$object = new stdClass();
object_assign($object, ['foo' => 'bar']);
echo $object->foo; // "bar"
public function send(Request $request)
{
// ...
return ok();
}
$periods = period('now', 4, '15 minutes');
$period = period('today', 'last day of this month', '3 days');
foreach (period('today', 'last day of this month', '3 days') as $datetime) {
echo $datetime->toDateTimeString();
}
// 2015-07-21 00:00:00
// 2015-07-24 00:00:00
// 2015-07-27 00:00:00
// 2015-07-30 00:00:00
$period = period('2015-07-06 00:00:00', '2015-07-26 00:00:00', '1 week');
period_from($period, '2015-07-13');
// 2015-07-13
$period = period('2015-07-06 00:00:00', '2015-07-26 00:00:00', '1 week');
period_from($period, '2015-07-06');
// 2015-07-13
pipe(10, [
fn($integer, $next) => $next($integer + 10);
fn($integer, $next) => $next($integer - 5);
])
// 15
remember('foo', 60, function() {
return 'bar';
})
remember('foo', function () {
return 'bar';
})
remember('foo', 60, function() {
return 'bar';
}, 20);
if (route_is('dahsboard.*')) {
return 'You are in the dashboard';
}
if ($rendered = shadow($mayRender, 'render')) {
return $rendered;
}
return response((string)$mayRender);
use App\Models\User;
sleep_between(3, 1000, fn() => User::query()->inRandomOrder()->value('name'))
// [
// 'john',
// 'michel',
// 'maria',
// ]
use App\Models\User;
use App\Notifications\Message;
return taptap(User::find(1))->notify(new Message('Hello!'))->save();
$path = undot_path('files.user_id_312.videos');
// files/user_id_312/videos/
until('now', 'next month')->total('days');
// 25
user()?->name;
// "John Doe"
weekend()->toDateTimeString();
// 2015-07-05 23:59:59
weekend('now')->toDateTimeString();
// 2015-07-13 23:59:59
weekstart()->toDateTimeString();
// 2015-06-28 00:00:00
weekstart('now')->toDateTimeString();
// 2015-07-06 00:00:00
$which = which_of('foo', [0 => 'baz', 1 => 'bar', 2 => 'foo'])
// 2
$which = which_of(
'foo',
['baz', 'bar', 'foo'],
fn($subject, $option) => $subject === $option ? 'cougar' : false)
);
// "cougar"
// 2015-07-12 17:30:00
yesterday();
// 2015-07-11 00:00:00