PHP code example of nohara / laravel-genpack

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

    

nohara / laravel-genpack example snippets




namespace App\Http\Controllers;

use Nohara\Genpack\Http\Controllers\BaseCrudController;
use Nohara\Genpack\Http\Controllers\Operations\ListOperation;
use Nohara\Genpack\Http\Controllers\Operations\CreateOperation;
use Nohara\Genpack\Http\Controllers\Operations\UpdateOperation;
use Nohara\Genpack\Http\Controllers\Operations\DeleteOperation;
use App\Models\Mahasiswa;

class MahasiswaCrudController extends BaseCrudController
{
    // Gunakan Trait Operations secara modular sesuai kebutuhan
    use ListOperation, CreateOperation, UpdateOperation, DeleteOperation;

    protected function setup()
    {
        // 1. Konfigurasi Entitas & Model
        $this->crud->setModel(Mahasiswa::class);
        $this->crud->setEntityNameStrings('Mahasiswa', 'Mahasiswa');
        $this->crud->setRoutePrefix('mahasiswa');
        $this->crud->setThemeStyle('porto'); // Opsi: 'classic' atau 'porto'

        // 2. Definisikan Kolom Tabel (DataTables)
        $this->crud->addColumn([
            'name'  => 'nim',
            'label' => 'NIM',
            'type'  => 'text',
        ]);
        $this->crud->addColumn([
            'name'  => 'nama',
            'label' => 'Nama Lengkap',
            'type'  => 'text',
        ]);

        // 3. Definisikan Field Input Form (Modal Form)
        $this->crud->addField([
            'name'        => 'nim',
            'label'       => 'NIM',
            'type'        => 'text',
            'placeholder' => 'Masukkan NIM...',
            '

use App\Http\Controllers\MahasiswaCrudController;

Route::get('mahasiswa', [MahasiswaCrudController::class, 'index'])->name('mahasiswa.index');
Route::get('mahasiswa/data', [MahasiswaCrudController::class, 'data'])->name('mahasiswa.data');
Route::get('mahasiswa/create', [MahasiswaCrudController::class, 'create'])->name('mahasiswa.create');
Route::post('mahasiswa', [MahasiswaCrudController::class, 'store'])->name('mahasiswa.store');
Route::get('mahasiswa/{id}/edit', [MahasiswaCrudController::class, 'edit'])->name('mahasiswa.edit');
Route::put('mahasiswa/{id}', [MahasiswaCrudController::class, 'update'])->name('mahasiswa.update');
Route::delete('mahasiswa/{id}', [MahasiswaCrudController::class, 'destroy'])->name('mahasiswa.destroy');

   Route::get('genpack/builder', function () {
       return view('vendor.genpack.builder');
   });
   
bash
# Publikasikan views (tabel utama & form modal)
php artisan vendor:publish --tag=genpack-views

# Publikasikan asset javascript (_list.js)
php artisan vendor:publish --tag=genpack-assets
bash
   php artisan vendor:publish --tag=genpack-views