Skip to content

Instantly share code, notes, and snippets.

View lavary's full-sized avatar

Reza Lavarian lavary

View GitHub Profile
@lavary
lavary / get_defined_vars.md
Last active August 29, 2015 14:01
Passing data to views without using sequential with() methods in Laravel 4

Python has a nice built-in function named locals() which returns a dictionary of local symbol table. This makes it easy to pass local variables to views in a single move.

I was wondering if PHP has such nice feature. I searched PHP's documentation and found this familiar built-in function: get_defined_vars()

get_defind_vars() Returns an array of all defined variables within the current scope.

Since PHP 5.0.0, the $GLOBALS variable is included in the results of the array returned.

You can use get_defind_vars() in a controller,closure or anywhere else you need:

@lavary
lavary / bootstrap-navbar.md
Last active June 17, 2018 19:10
Making multiple menus in a Bootstrap navbar

#Laravel Menu: Bootstrap Navbar

It is possible to create multiple menu instances in a single navbar. I'm going to use Bootstrap default navbar for this demonstration:

First of all we create our menu objects in app/routes.php or app/start/global.php or any other place you desire as long as it is auto loaded when a request hits your application.

routes.php

php
export const validateNif = function (value) {
return {
valid: validateNIF(value),
errorMessage: 'NIF não válido'
}
}
function validateNIF (value) {
if (!/[123]\d{8}/.test(value)) {
return false
export const validateCC = function (value) {
return {
valid: validate(value),
errorMessage: 'O número do Cartão de Cidadão não é válido'
}
}
const CHAR = {
'0': 0,
'1': 1,
export const validateBI = function (NBI, checkDigit) {
return {
valid: validateBI(NBI, checkDigit),
errorMessage: 'BI não válido'
}
}
const NBI_LENGTH = 9