PHP code example of jan-dolata / crude-crud

1. Go to this page and download the library: Download jan-dolata/crude-crud 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/ */

    

jan-dolata / crude-crud example snippets




namespace App\Engine\Crude;

use Crude;
use CrudeListInterface;
use CrudeFromModelTrait;

class ListName extends Crude implements
    CrudeListInterface
{

    use CrudeFromModelTrait;

    public function __construct()
    {
        $this->setModel(new \App\Engine\Models\ModelName);

        $this->prepareCrudeSetup();
    }

}

return view('viewName', [
    'crudeSetup' => [(new \App\Engine\Crude\ListName)->getCrudeSetupData()]
]);

    public function up()
    {
        Schema::create('books', function (Blueprint $table) {
            $table->increments('id');
            $table->string('tile');
            $table->integer('order');
            $table->timestamps();
        });
    }

namespace App\Models;

class Book extends \Illuminate\Database\Eloquent\Model
{
    protected $fillable = ['title'];
}

use Auth;

class BooksList extends \Crude implements \CRUDInterface, \CrudeOrderInterface
{
    use \CrudeFromModelTrait;

    public function __construct()
    {
        $this->setModel(new \App\Models\Book);

        $this->prepareCrudeSetup();

        $this->crudeSetup
            ->setTitle('List of books')
            ->setTrans(['id' => 'Id', 'title' => 'Title', 'order' => '#'])
            ->setColumnFormat('title', 'longtext');

        $this->storeInFirstPlace();

        if (! Auth:user()->cannotOrderListOfBooks())
            $this->crudeSetup->useOrderedList('title');
    }
}
 bash
$ php artisan vendor:publish --provider="JanDolata\CrudeCRUD\CrudeCRUDServiceProvider"
$ php artisan migrate