2017 © Pedro Peláez
 

library nullable

chain calls on object whatever the object is null or not

image

xiyusullos/nullable

chain calls on object whatever the object is null or not

  • Friday, March 24, 2017
  • by xiyusullos
  • Repository
  • 1 Watchers
  • 12 Stars
  • 2,153 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Nullable - Chain calls on Null for PHP

Installation

Install the latest version with, (*1)

composer require xiyusullos/nullable

Usage

Basic Usage

<?php

use xiyusullos\Nullable;

class Obj
{
    use Nullable;

    // ...
}

$obj = new Obj();
echo $obj->a->b->c;

Laravel Usage

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use xiyusullos\Nullable;

class Profile extends Model
{
    // supposed an attribute of departmentName
    use Nullable;

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    // ...
}

class User extends Model
{
    use Nullable;

    public function profile()
    {
        return $this->hasOne(Profile::class);
    }

    // ...
 }

class Blog extends Model
{
    use Nullable;

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    // ...
}

// wanna get the writer's department name who posted the blog #1

// without Nullable
$blog = Blog::find(1);
$user = $blog->user;
if ($user) {
    $profile = $user->profile;
    if ($profile) {
        $departmentName = (string) $profile->departmentName;
    }
} // that's so annoying!

// with Nullable
$blog = Blog::find(1);
$departmentName = (string) $blog->user->profile->departmentName;

About

Author

xiyusullos, (*2)

License

Nullable is licensed under the MIT License - see the LICENSE file for details, (*3)

The Versions

24/03 2017

dev-master

9999999-dev https://github.com/xiyusullos/nullable

chain calls on object whatever the object is null or not

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar xiyusullos

laravel eloquent null object chain calls

22/03 2017

0.2.0

0.2.0.0 https://github.com/xiyusullos/nullable

chain calls on object whatever the object is null or not

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar xiyusullos

object chain null

22/03 2017

0.1.0

0.1.0.0 https://github.com/xiyusullos/nullable

chain calls on object whatever the object is null or not

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Avatar xiyusullos

object chain null