PHP code example of dilneiss / laravel-repository

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

    

dilneiss / laravel-repository example snippets

 
use JetBox\Repositories\Traits\EnvironmentTrait

namespace App\Constants;

use JetBox\Repositories\Constants\AppConstants as BaseAppConstants;

final class AppConstants extends BaseAppConstants
{
    const ROLE_VISITOR = 'visitor';
    const ROLE_EDITOR = 'editor';

    const PERMISSION_VIEW_BLOG = 'view_blog';
}

namespace App\Repositories;

class UserRepository extends AbstractRepository
{

}

namespace App\Repositories;

use App\Models\User;

class UserRepository extends AbstractRepository
{
   /**
    * @var string
    */
   protected $model = User::class;

   /**
    * Global OrderBy Column
    * @var string
    */
   public $orderByColumn = 'created_at';

   /**
    * Global OrderBy Direction
    * @var string
    */
   public $orderByDirection = 'desc';
}

namespace App\Http\Controllers;

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\View\View;
use App\Repositories\UserRepository as UserR;

class UserController extends BaseController {

    /**
     * @var $users
     */
    protected $users;

    /**
    * UserController constructor.
    * @param UserR $users
    */
    public function __construct(UserR $users)
    {
        $this->users = $users;
    }

    /**
    * @return Application|Factory|View
    */
    public function index()
    {
        $users = $this->users->all();

        return view('users', compact('users'));
    }

}

$users = $this->users->all();

$user = $this->users->find($id);
terminal
php artisan repository:install
terminal
php artisan make:repository UserRepository