PHP code example of agenciamaior / laravel_boilerplate
1. Go to this page and download the library: Download agenciamaior/laravel_boilerplate library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
agenciamaior / laravel_boilerplate example snippets
Route::get('/', function() {
return view('welcome');
});
Route::get('/', 'HomeController@index')->name('home');
\AgenciaMaior\LaravelBoilerplate\LaravelBoilerplateServiceProvider::routes();
//...
const ROLE_ADMIN = 0;
const ROLE_COMMON = 1;
public static function roles() {
return [
self::ROLE_ADMIN => 'Administrador',
self::ROLE_COMMON => 'Comum',
];
}
public function getRoleStringAttribute() {
return self::roles()[$this->role];
}
//...
$user->role = \App\User::ROLE_ADMIN;
// Equivalente a:
$user->role = 0;
// ...
class AuthServiceProvider extends ServiceProvider
{
// ...
public function boot()
{
$this->registerPolicies();
Gate::before(function ($user) {
if ($user->role == User::ROLE_ADMIN) {
return true;
}
});
// ...
}
}
\AgenciaMaior\LaravelBoilerplate\LaravelBoilerplateServiceProvider::routes();
Route::group(['prefix' => '/users'], function () {
Route::post('/first-user', 'UsersController@storeFirstUser')->name('users.first-user');
Route::get('/profile', 'UsersController@profile')->name('users.profile');
Route::post('/profile', 'UsersController@updateProfile')->name('users.save-profile');
Route::post('/check-email', 'UsersController@checkEmail')->name('users.check-email');
Route::post('/check-profile-email', 'UsersController@checkProfileEmail')->name('users.check-profile-email');
Route::post('/check-profile-password', 'UsersController@checkProfilePassword')->name('users.check-profile-password');
Route::get('/block/{user}', 'UsersController@block')->name('users.block');
Route::get('/unblock/{user}', 'UsersController@unblock')->name('users.unblock');
});
Route::resource('/users', 'UsersController');
{{ Form::bsText('data', 'Data', ['class' => 'datepicker date-mask']) }}
{{ Form::bsFile('arquivo', 'Arquivo <small>máx 2MB</small>') }}
{{ Form::bsText('cpf', 'CPF', ['class' => 'cpf-mask']) }}
{{ Form::bsText('cnpj', 'CNPJ', ['class' => 'cnpj-mask']) }}
{{ Form::bsText('cpf_cnpj', 'CPF/CNPJ', ['class' => 'cpf-cnpj-mask']) }}
{{ Form::bsTextarea('editor', 'Editor', ['class' => 'editor']) }}
$date = '03/05/2019';
$newDate = $this->parseDate($date); // 2019-05-03
$price = 'R$ 300,00';
$newPrice = $this->parseCurrency($price); // 300
const ESTADOS_BRASILEIROS = [
'AC' => 'Acre',
'AL' => 'Alagoas',
'AP' => 'Amapá',
'AM' => 'Amazonas',
'BA' => 'Bahia',
'CE' => 'Ceará',
'DF' => 'Distrito Federal',
'ES' => 'Espírito Santo',
'GO' => 'Goiás',
'MA' => 'Maranhão',
'MT' => 'Mato Grosso',
'MS' => 'Mato Grosso do Sul',
'MG' => 'Minas Gerais',
'PA' => 'Pará',
'PB' => 'Paraíba',
'PR' => 'Paraná',
'PE' => 'Pernambuco',
'PI' => 'Piauí',
'RJ' => 'Rio de Janeiro',
'RN' => 'Rio Grande do Norte',
'RS' => 'Rio Grande do Sul',
'RO' => 'Rondônia',
'RR' => 'Roraima',
'SC' => 'Santa Catarina',
'SP' => 'São Paulo',
'SE' => 'Sergipe',
'TO' => 'Tocantins'
];
{{ Form::bsSelect('estados', 'Estados', \App\Http\Controller::ESTADOS_BRASILEIROS) }}
sh
$ php artisan boiler:install
sh
$ php artisan migrate
html
@can('create', \App\User::class)
<a href="{{ route('users.create') }}" class="btn btn-primary"><i class="fa fa-plus"></i> Novo Usuário</a>
@endcan
@foreach($users as $u)
@can('edit', $u)
<a href="{{ route('users.edit', ['user' => $u]) }}" class="btn btn-default btn-sm"><i class="fa fa-pencil-alt"></i> Editar</a>
@endcan
@endforeach