Skip to content

Instantly share code, notes, and snippets.

View permatis's full-sized avatar

defri permatis

  • Indonesia
View GitHub Profile
@permatis
permatis / AclMiddleware.php
Created March 22, 2016 07:41
Acl with Middleware.
<?php
namespace App\Http\Middleware;
use Closure;
use App\Models\Permission;
class AclMiddleware
{
private $restfull = [
@permatis
permatis / tagged.php
Created March 14, 2016 09:37
Filtering tags if exists in database records.
<?php
/**
* Filter tag if exists
* @param string $input Get value from input name
* @return array All tags is don't exists
*/
private function tagged($input)
{
$newTags = [];
$tags = explode(',', $input);
@permatis
permatis / getallmodel.md
Last active March 10, 2016 03:48
Create simple helper for get a list all of model in laravel.

How to use

Describe your path where models directory, set your namespace model and adding a prefix if you want (optional).

$modelPath = app_path().'\\Models\\';
$namespace = 'App\Models\\';
dd(getAllModels($modelPath, $namespace));
@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

@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 / 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 / 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 / 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 / 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 / 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') }