PHP code example of marceloxp / laravel

1. Go to this page and download the library: Download marceloxp/laravel 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/ */

    

marceloxp / laravel example snippets


	public function boot()
	{
        // ...
		$publishes = [ base_path('vendor/summernote/summernote/dist') => public_path('vendor/summernote') ];
		$this->publishes($publishes, 'summernote');
	}

Datasite::add('csrf_token', csrf_token());
Datasite::add(compact('url'));

datasite_add('csrf_token', csrf_token());
datasite_add(compact('url'));

// Time in minutes
Cached::get('brasil', 'states', $states, 10);
Cached::get('brasil', 'regions', $regions, 10);
$result = Cached::get
(
	'group_name',
	['name_1', 'name_2'],
	function() use ($args)
	{
		return \App\Models\Category::get()->first();
	},
	5
);
Cached::forget('admin', 'states');
Cached::forget('admin'); // Clear all files on admin prefix
Cached::flush();         // Clear all cache

MetaSocial::use('sobre');
MetaSocial::append('title', ' - Fale Conosco');
MetaSocial::set('description', 'Entre em contato conosco.');
Metasocial::print();

$json_data = HttpCurl::json('https://viacep.com.br/ws/05415030/json/');

$address = Cep::get('04045-004');      // Returns Adddress
$valid   = Cep:valid('04045-004');     // Returns true
$valid   = Cep:valid('5');             // Returns false
$masket  = Cep:mask('4045004');        // Returns '04045-004'
$masket  = Cep:toNumeric('04045-004'); // Returns 4045004

return Result::success('Dados cadastrados com sucesso.');
return Result::success('Dados cadastrados com sucesso.', ['id': 396]);
return Result::error('Ocorreu um erro na gravação do registro');
return Result::cached('', { 'id': 1, 'uf': 'sp' });
return Result::undefined();   // Ocorreu um erro na solicitação.
return Result::invalid();     // Entrada de dados inválida.
return Result::exception($e); // Ocorreu um erro na solicitação.

RouteLang::lang();                    // returns current language, string empty if is default language (pt-br). Ex.: ''
RouteLang::lang('pt-br');             // returns current language, string empty if is default language. Ex.: ''
RouteLang::lang('en');                // returns current language, string empty if is default language. Ex.: 'en'
RouteLang::root();                    // returns current site root language
RouteLang::rootUrl();                 // returns current site full root url language
RouteLang::rootUrl('en');             // returns full root url to language [enb]
RouteLang::prefix('/sobre');          // Translate prefix to current language
RouteLang::route($route, '/empresa'); // Translate url route to current language
RouteLang::getDefaultLocale();        // Returns app default locale config
RouteLang::getCurrentLocale();        // Returns app current locale config (dynamic)

// ['inativo','não','i','n','no','0','excluido'])) ? 'red' : 'green';
echo admin_label_status($value);

// bootstrap badge
echo admin_badge_status($value);

// ['RJ' => 'Rio de Janeiro', 'SP' => 'São Paulo']
echo admin_select($p_field_name, $p_options, $p_field_value, $p_

echo alert_success('Mensagem enviada com sucesso.');
echo alert_danger('Ocorreu um erro na solicitação!');
echo print_alert(); // Auto print messages from Session

echo db_database_name();                                // Returns current database name
echo db_comment_table('table_name', 'comment_table');   // Define table comment
echo db_get_comment_table('table_name');                // Returns table comment
echo db_get_pivot_table_name(['videos','tags'], true);  // Returns pivot table name (Ex: blp_tag_video)
echo db_get_pivot_scope_name([Model1, Model2]);         // Returns a pivot scope name (Ex: db_get_pivot_scope_name([Video::class, Tag::class]) => tagVideo)
echo db_get_primary_key('table_name');                  // Returns id
echo db_get_name('table_name', 10);                     // Returns `name` field value
echo db_select_one(Model, ['fields'], ['where'], true); // Returns only one register (Ex: echo db_select_one(\App\Models\City::class, ['id','name'], ['name' => 'São Paulo'], true) => {"id":5325,"name":"São Paulo"})
echo db_select_id(Model, ['where'], false);             // Returns only if by where (Ex: echo db_select_id(\App\Models\City::class, ['name' => 'São Paulo'], true) => 5325)
echo db_model_to_table_name('SchameName\City');         // Returns table name from model name => cities
echo db_table_name_to_model('cities');                  // Returns model name from table name => City
echo db_table_name_to_model_path('cities');             // Returns path model from table name => \App\Models\City
echo db_table_name_to_field_id('cities');               // Returns relative field id to another table => city_id
echo db_table_exists('cities');                         // Returns if table exists in database

// Add host and app version
javascript('/js/main.js');
<script type="text/javascript" src="https://wwww.site.com.br/js/main.js?v=0.0.1"></script>>

css('/css/style.css');
<link rel="stylesheet" type="text/css" href="https://wwww.site.com.br/css/style.css?v=0.0.1">

app_version('0.0.3')
// returns version value from config/app.php or default.

return response($result)->withHeaders(cached_headers($result));

ddd($var);

echo dic('Página Inicial');
{{ dic('Página Inicial') }}

echo lang_home_link();     // returns current language root url
echo lang_home_link('en'); // returns root url for language [en]

echo str_mask('04045004', '##.###-###'); // Returns '04.045-004'
echo str_mask('04045004', '#####-###');  // Returns '04045-004'
echo str_plural_2_singular('corações');  // Returns 'coração';

echo str2bool('true');  // Returns true;
echo str2bool('false'); // Returns false;
echo str2bool('foo');   // Returns false;

// Example:
admin_table_index_set_button('users', 'btn-send-mail', 'many', 'btn-success', true, 'fas fa-envelope', 'Send Mail', 'Deseja enviar os e-mails para os registros selecionados?');

// Ajax Controller:
public function onUsersBtnSendMail(Request $request, $ids)
{
	return Result::success('Solicitação efetuada com sucesso.', $ids);
}
bash
php artisan migrate:refresh --seed