{"repo":"imanghafoori1/laravel-nullable","free":true,"listed":false,"github":"https://github.com/imanghafoori1/laravel-nullable","clone":"git clone https://github.com/imanghafoori1/laravel-nullable.git","description":"Functional programming paradigms in laravel to avoid run-time errors.","language":"PHP","stars":151,"topics":["laravel","laravel-nullable","functional-laravel","laravel-utility"],"license":"MIT","category":"api-integrations-sdks","readme_excerpt":"Laravel Nullable Do not let \"null\" to impersonate your objects. Functional programming paradigm in laravel Built with :heart: for every smart laravel developer Null is usually used to represent a missing value (for ex when we can't find a row with a partcular Id we return null) And that is the BAD IDEA, we are going to kill off !!! :fire: Installation: This package exposes a nullable() global helper function with which you can wrap variables which sometimes are object and sometimes null . Consider this: Now this code is working fine But... What if the user with ID of 1 gets deleted in future ?! and crap ! :anguished: So if you forget to handle the null with an if statement, you will have errors. You need something to FORCE you and the users of your class methods to handle the null cases. To prevent such errors, you should code like this: :arrow forward: Nullables to rescue !!! To refactor the code above, first You have to change your repo class : The above code returns 2 types, and That is the source of confusion for method callers. They get ready for one type, and forget about the other. Let's do a small change to it: :bell: Now our method consistently returns Nullable objects, no matter what :) After this change, no one can have access to the real meat of your repo (in this case User object) unless he/she gives a way to handle the null case. No if(is null()) is required, No exception handling is required. Remember PHP does not force us to write that if, and we as humen alwa","default_branch":null,"files":null,"tree":[],"storefront":"/r/imanghafoori1","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/imanghafoori1/laravel-nullable/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}