Skip to content

Instantly share code, notes, and snippets.

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

Mauricio Rodrigues zabaala

🏠
Working from home
View GitHub Profile
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Request;
class UFValidatorMiddleware
{
/**
* @const array
@zabaala
zabaala / BadAbstractRepository.php
Last active January 26, 2018 18:46
BadAbstractRepository.php
<?php
abstract class BadAbstractRepository
{
protected $model;
/**
* Recupera todas as entidades de forma genérica.
*/
public function getAll()
@zabaala
zabaala / Controller.php
Created January 26, 2018 11:23
Direct access to repository
<?php
class DoctorsController extends Controller
{
public function index(DoctorRepositoryInterface $doctorRepository)
{
$doctors = $doctorRepository->getAll('id', 'desc');
$total = $doctors->total();
// ...
}
<?php
// ...
class DoctorsController extends Controller
{
public function store(Request $request)
{
try {
$command = new CreateNewDoctorCommand($request->all());
$command->handle();
} catch (CommandException $commandException) {
<?php
class User
{
public function __construct($name, $email, $password)
{
$this->name = $name;
$this->email = $email;
$this->password = bcrypt($password);
}
<?php
class UserRepository implements UserRepositoryInterface
{
private $userEloquentModel;
public function __construct(UserModel $userModel)
{
$this->userEloquentModel = $userModel;
}
@zabaala
zabaala / UserRepositoryInterface.php
Created January 26, 2018 18:43
Repository: the right way
<?php
interface UserRepositoryInterface
{
public function __construct(UserModel $userModel);
public function createNewUser(User $user);
public function UpdateUserById(User $user, $id);
}
<?php
class UserModel extends Illuminate\Database\Eloquent\Model
{
protected $table = 'users';
}
<?php
$anuncios = Anuncio::select([
'anuncios.id',
'anuncios.titulo',
'anuncios.descricao',
DB::raw('(select if(count(anuncios_favoritados.id) > 0, 'favorito', 'nao_favorito') from anuncios_favoritados where user_id = "' . Auth::user()->id . '") as favoritado ')
])->get()
<?php
// ...
class DbCouponRepository implements CouponRepositoryInterface
{
/**
* @const int
*/
const PAGE_SIZE = 25;