sheenazien8/hascrudactions

CRUD tirelessly 💤

1.0.6 2021-05-02 01:52 UTC

README

68747470733a2f2f692e6962622e636f2f76774e337667322f47726f75702d332e706e67

Hascrudaction

Latest Version on Packagist Build Status Total Downloads

This package allows you to build a CRUD with tiny Controller and keep the pattern are consitent.

Lifecycles

Method Path Function Repository Function Route Name
GET base_domain/path/ ControllerClass@index RepositoryClass@datatable path.index
GET base_domain/path/create ControllerClass@create ----- path.create
GET base_domain/path/{id} ControllerClass@show ----- path.show
POST base_domain/path/ ControllerClass@store RepositoryClass@create path.store
GET base_domain/path/{id} ControllerClass@edit ----- path.edit
PUT base_domain/path/{id} ControllerClass@update RepositoryClass@update path.update
DELETE base_domain/path/{id} ControllerClass@destroy RepositoryClass@delete path.destroy
DELETE base_domain/bulkDestroy/ ControllerClass@bulkDestroy RepositoryClass@bulkDestroy path.bulkDestroy

Requirements

Installation

You can install the package via composer:

composer require sheenazien8/hascrudactions

Configuration

Laravel Configuration

php artisan vendor:publish --provider="Sheenazien8\Hascrudactions\HascrudactionsServiceProvider"

Register the provider class in config/app.php

"providers" => [
    Sheenazien8\Hascrudactions\HascrudactionsServiceProvider::class,
]

Lumen Configuration

mkdir -p config
cp vendor/sheenazien8/hascrudactions/config/config.php config/config.php

Basic Usage

First, Generate the Hascrud route with php artisan hascrudaction:make Employee this command will be generate a few class and file views, Example.

  • App\Http\Controllers\EmployeeController
  • App\Http\Requests\Employee\.*
  • App\Repositories\EmployeeRepository
  • resources/views/employee/.*

And Setup the datatable.

Install Datatable Package and Setup

Install Composer

composer require yajra/laravel-datatables

Install Assets

yarn add datatables.net-bs4 datatables.net-buttons-bs4

Register datatables.net in resources js and css file

// Js file
require('bootstrap');
require('datatables.net-bs4');
require('datatables.net-buttons-bs4');

// Scss file
@import "~datatables.net-bs4/css/dataTables.bootstrap4.css";
@import "~datatables.net-buttons-bs4/css/buttons.bootstrap4.css";

Compile Assets

yarn dev / watch / prod

Next, you can add the path in routes/web.php, edit file config in config/hascrudactions.php for wrapper blade layouts and javascript views, add Traits HasLaTable in Model Class Employee.

routes/web.php

Route::hascrud('employee');

config/hascrudactions.php

/**
 * Wrapper view, you can adjust static view like footer and header
 * put file in views path
 * layouts:
 * section:
 * javascript:
 */
'wrapper' => [
    'layouts' => 'layouts.app',
    'section' => 'content',
    'javascript' => 'javascript'
]

app/Employee.php

use Sheenazien8\Hascrudactions\Traits\HasLaTable;

class Employee extends Model
{
    use HasLaTable;
    //
}

And the last, you can define what columns you want to display in the index view in resources/views/employee/components/table.blade.php, and then you must define what columns you want to add or edit in the model Employee with $fillable property and form view resources/views/employee/components/form.blade.php, and also you can get the binding data from controller with the $data variable name.

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.