Skip to content

Instantly share code, notes, and snippets.

View insign's full-sized avatar
🇧🇷
being open-sourcerer

Hélio insign

🇧🇷
being open-sourcerer
View GitHub Profile
@insign
insign / User.php
Created November 23, 2015 16:32
Problemas com relacionamentos - laravel
<?php
// APENAS A PARTE RELEVANTE
public function fotos()
{
return $this->hasMany('\App\UserFoto');
}
?>
@insign
insign / 2014_10_29_181650_create_users_fotos_table.php
Created November 23, 2015 16:34
Problemas com relacionamentos - laravel (Error: Call to undefined method Illuminate\Database\Query\Builder::mini())
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateUsersFotosTable extends Migration
{
/**
* Run the migrations.
<?php
class ItemsController extends BaseController {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index() {
@insign
insign / app\routes.php
Created September 17, 2013 06:46
Resource bug
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
@insign
insign / calcular.php
Created October 8, 2013 03:48
Cálculo de Prescrição (simulação)
<?php
require_once 'cdp.class.php';
$cdp = new CalculoDePrescricao;
$cdp->data_do_crime = $_POST['data_do_crime'];
$cdp->data_da_denuncia = $_POST['data_da_denuncia'];
$cdp->idade_criminoso = $_POST['idade_criminoso'];
$cdp->pena_maxima = $_POST['pena_maxima'];
<?php
// This will create a product, apply a discount since it is a new
// product, and send a notification via email
public function store()
{
// Create product from request
$product = Product::create($request->all());
// Get the discount to be applied
$discount = Discount::byType('newProduct');
<?php
protected function createProduct()
{
}
protected function applyDiscount($type, $product)
{
}
<?php
protected function createProduct()
{
return Product::create($this->request->all());
}
protected function applyDiscount($type, $product)
{
$discount = Discount::byType($type);
<?php
// This will create a product, apply a discount since it is a new
// product, and send a notification via email
public function store()
{
// Create product from request
$product = Product::create($request->all());
// Get the discount to be applied
$discount = Discount::byType('newProduct');
<?php
public function store()
{
$product = $this->createProduct();
$this->applyDiscount('newProduct', $product);
$this->notifyUsersVia('email');
return 'Success';
}