Skip to content

Instantly share code, notes, and snippets.

View permatis's full-sized avatar

defri permatis

  • Indonesia
View GitHub Profile
@permatis
permatis / project.sql
Last active August 29, 2015 14:09
Menampilkan hasil pendapatan pegawai dan per project.
mysql> create table if not exists kontributor (id int not null auto_increment, nama varchar(45), primary key(id));
Query OK, 0 rows affected (0.10 sec)
mysql> create table if not exists project ( id int not null auto_increment, namaproject varchar(45), biaya int, primary key(id));
Query OK, 0 rows affected (0.46 sec)
mysql> create table if not exists relasi_kontributor ( kontributor_id int not null, project_id int not null
-> );
Query OK, 0 rows affected (0.45 sec)
@permatis
permatis / replace_mutidotted.php
Last active August 29, 2015 14:19
This function for replace multidotted with string in array.
<?php
//Example array subject
$array1 = [
'Name',
': ...',
'Tab',
'Semarang, ........'
];
@permatis
permatis / app.php
Created April 27, 2015 05:18
Create setting SwiftMailer in Slim Framework.
$app->mailer = function () {
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', '465', 'ssl')
->setUsername('[email protected]')
->setPassword('password');
$mailer = Swift_Mailer::newInstance($transport);
return $mailer;
};
@permatis
permatis / L5_ajax.php
Last active December 2, 2015 06:53
Mengirim data dengan method (post/get) dengan Laravel 5 dan Ajax menggunakan csrf.
/**
* Mengirim data method get
* /
// index.html
<!-- Header -->
<meta name="_token" content="{!! csrf_token() !!}"/>
<!-- Footer -->
$.ajaxSetup({
headers: { 'X-CSRF-Token' : $('meta[name="_token"]').attr('content') }
@permatis
permatis / 1Instruksi.md
Last active November 25, 2019 02:37
Membuat helper tanggal Indonesia di laravel 5 dengan Carbon.

Membuat Helper di Laravel 5

Berikut ini adalah langkah-langkah membuat helper di laravel 5 dengan contoh kasus membuat helper tanggal / datetime ke Indonesia.

  • Buat folder Helpers atau lainnya didalam folder App.
  • Membuat file Service Provider terlebih dahulu. gunakan perintah php artisan make:provider HelperServiceProvider
  • Kemudian buka file HelperServiceProvider.php di dalam folder App/Providers/
  • Tambahkan kode dibawah ini didalam fungsi register()
@permatis
permatis / iWantPartAmountNumber.php
Created December 11, 2015 19:40
This function create for part or split amount a number or record from database.
<?php
/**
* Output like this :
* array('1' => array('1' => '1','2' => '2'), '2' => array('3' => '3', '4' => '4'), '3' => array('5' => '5'));
*/
function pecah_total($total, $limit)
{
for ($i=1; $i <= floor($total/$limit)+1; $i++) {
@permatis
permatis / ExampleSeeder.stub
Last active December 19, 2015 02:24
This file for make records to part. For example, i create seeder by laravel.
<?php
use App\{{ table }};
use Illuminate\Database\Seeder;
class {{ table }}Part{{ key }}Seeder extends Seeder
{
/**
* Run the database seeds.
*
@permatis
permatis / syncAlwaysNull.php
Created January 12, 2016 15:02
How to resolve problem about many to many relation with 'sync' function in laravel 5.
<?php
//Problem 1 : Argument 1 passed to Illuminate\Database\Eloquent\Relations\BelongsToMany::formatSyncList() must be of the type array, null given, called
$tabelA->tabelB()->sync($request->get('col1'), $request->get('col2'));
//Problem 2 : Integrity constraint violation: 1048 Column 'col2_id' cannot be null
$tabelA->tabelB()->sync([$request->get('col1'), $request->get('col2')]);
//How to resolve
$data = array_slice($request->all(), 1); //remove _token post data
@permatis
permatis / simpleDeclareFunction.js
Created January 21, 2016 12:27
How to resolve problems when you declare a variable in a function or jquery plugin too much.
/**
* As an example, I use jquery plugins Chosen.
*/
$('#firstid').chosen({});
$('#secondid').chosen({});
$('#moreid').chosen({});
/**
* How to resolve : Get id attribute from tag select.
*/
@permatis
permatis / MAKE TO BREADCRUMB.MD
Last active March 10, 2016 03:30
It is helper for easy and simple make breadcrumbs in laravel.

###How to use ### I referenced from stackoverflow This helper required package laravelcollective/html.

For review : <?php breadcrumb(); ?> //php {!! breadcrumb('Dashboard', '&gt;') !!} //laravel