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));| <?php | |
| namespace App\Http\Middleware; | |
| use Closure; | |
| use App\Models\Permission; | |
| class AclMiddleware | |
| { | |
| private $restfull = [ |
| <?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); |
| /** | |
| * As an example, I use jquery plugins Chosen. | |
| */ | |
| $('#firstid').chosen({}); | |
| $('#secondid').chosen({}); | |
| $('#moreid').chosen({}); | |
| /** | |
| * How to resolve : Get id attribute from tag select. | |
| */ |
| <?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 |
| <?php | |
| use App\{{ table }}; | |
| use Illuminate\Database\Seeder; | |
| class {{ table }}Part{{ key }}Seeder extends Seeder | |
| { | |
| /** | |
| * Run the database seeds. | |
| * |
| <?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++) { |
Berikut ini adalah langkah-langkah membuat helper di laravel 5 dengan contoh kasus membuat helper tanggal / datetime ke Indonesia.
App.php artisan make:provider HelperServiceProviderregister()| /** | |
| * Mengirim data method get | |
| * / | |
| // index.html | |
| <!-- Header --> | |
| <meta name="_token" content="{!! csrf_token() !!}"/> | |
| <!-- Footer --> | |
| $.ajaxSetup({ | |
| headers: { 'X-CSRF-Token' : $('meta[name="_token"]').attr('content') } |