Skip to content

Instantly share code, notes, and snippets.

View emboh's full-sized avatar
🏠
Working from home

Hans Maatita emboh

🏠
Working from home
  • Sydney
  • 08:15 (UTC +11:00)
View GitHub Profile
@emboh
emboh / BetterResponseStatus.php
Last active August 31, 2020 07:34
Write better response status for cleaner code
<?php
use App\Http\Controllers\Controller;
// choose one of these following Response class, or use Response Facade \ alias
// use Symfony\Component\HttpFoundation\Response;
// use Illuminate\Http\Response;
// use Illuminate\Support\Facades\Response;
class BetterResponseStatus extends Controller
@emboh
emboh / laravel_custom_helpers.txt
Last active August 3, 2020 02:02
Laravel custom helpers
//app/helpers.php
if (! function_exists('foo_bar')) {
function foo_bar($acme)
{
//
}
}
//composer.json
@emboh
emboh / debug_controller_method_tinker.txt
Last active August 7, 2020 00:09
Debug controller method with tinker
$controller = app()->make('App\Http\Controllers\MyController');
app()->call([$controller, 'myMethodName'], []);
@emboh
emboh / laravel_login_by_username.txt
Last active July 31, 2020 01:16
Get the login username to be used by the controller
/**
* Get the login username to be used by the controller.
*
* @return string
*/
public function username()
{
$login = request()->input('username');
$field = filter_var($login, FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
@emboh
emboh / Uuid.php
Last active August 15, 2020 10:24
Laravel UUID Trait
<?php
namespace App\Traits;
use Illuminate\Support\Str;
trait Uuid
{
/**
* The "booted" method of the model.