Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
シティ・ポップは好きです。

Mustafa Akçakaya mgsmus

💭
シティ・ポップは好きです。
View GitHub Profile
View laravel_package_service_provider.php
<?php
namespace Mgsmus\MyPackage\Providers;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;
class MyPackageServiceProvider extends ServiceProvider
{
/**
View laravel_package_event_service_provider.php
<?php
namespace Mgsmus\MyPackage\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider;
class MyPackageEventServiceProvider extends EventServiceProvider
{
protected $listen = [
\Mgsmus\MyPackage\Events\EntityCreated::class => [
View laravel_global_event_listen.php
<?php
//EventServiceProvider::boot()
public function boot()
{
parent::boot();
Event::listen('eloquent.created: App\User', function ($user) {
// $user burada yeni oluşturulmuş User modeli...
});
View weak_references.php
<?php
class MyClass {
public function __destruct() {
echo "Destroying object!\n";
}
}
$o1 = new MyClass;
$r1 = new Weakref($o1);
View coalesce_assign_operator.php
<?php
// Bunun yerine
$this->request->data['comments']['user_id'] = $this->request->data['comments']['user_id'] ?? 'value';
// Şu şekilde bir kullanım mümkün.
// Kod tekrarının önüne geçilmiş oluyor.
$this->request->data['comments']['user_id'] ??= 'value';
View spread_operator_in_array_expression.php
<?php
$arr1 = [1, 2, 3];
$arr2 = […$arr1]; //[1, 2, 3]
$arr3 = [0, …$arr1]; //[0, 1, 2, 3]
$arr4 = array(…$arr1, …$arr2, 111); //[1, 2, 3, 1, 2, 3, 111]
$arr5 = […$arr1, …$arr1]; //[1, 2, 3, 1, 2, 3]
function getArr() {
return ['a', 'b'];
View contravariant_parameters.php
<?php
interface Concatable {
function concat(Iterator $input);
}
class Collection implements Concatable {
// Sadece Iterator değil tüm iterable tipleri kabul edecek
function concat(iterable $input) {}
}
View covariant_returns_7.4.php
<?php
interface Factory {
function make(): object;
}
class UserFactory implements Factory {
function make(): User {}
}
View arrow_functions_7.4.php
<?php
$y = 1;
$total = fn($x) => $x + $y;
View typed_properties_7.4.php
<?php
class User {
public int $id;
public string $name;
public function __construct(int $id, string $name) {
$this->id = $id;