PHP code example of alxarafe / resource-eloquent

1. Go to this page and download the library: Download alxarafe/resource-eloquent 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/ */

    

alxarafe / resource-eloquent example snippets


use Alxarafe\ResourceController\AbstractResourceController;
use Alxarafe\ResourceController\Contracts\RepositoryContract;
use Alxarafe\ResourceController\Contracts\TransactionContract;
use Alxarafe\ResourceEloquent\EloquentRepository;
use Alxarafe\ResourceEloquent\EloquentTransaction;
use App\Models\Product; // Your Eloquent model

class ProductController extends AbstractResourceController
{
    // ... basic controller configuration ...

    protected function getRepository(string $tabId = 'default'): RepositoryContract
    {
        return new EloquentRepository(Product::class);
    }

    protected function getTransaction(): TransactionContract
    {
        // Get the DB connection from Laravel or Capsule
        return new EloquentTransaction(\Illuminate\Support\Facades\DB::connection());
    }
}