PHP code example of luuka / laravel-base-repository
1. Go to this page and download the library: Download luuka/laravel-base-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/ */
namespace Luuka;
use Luuka\LaravelBaseRepository\Repository\BaseRepository;
//use Your Model
/**
* Class UserRepository.
*/
class UserRepository extends BaseRepository
{
/**
* @return string
* Return the model
*/
public function model()
{
//return YourModel::class
}
}
namespace App\Models;
use Luuka\LaravelBaseModel\Model\BaseModel;
class YourModel extends BaseModel
{
// Filter with variable
protected $filterable = ['name'];
// Sort with variable;
protected $sortable = ['name' => 'desc'];
// Custom filter
public function filterSearch($query, $value)
{
return $query->where('name', 'LIKE', '%' . $value . '%');
}
// Custom sorts
public function sortName($query)
{
return $query->orderBy('name', 'desc');
}
}
namespace App\Http\Controllers\Backend;
use App\Http\Controllers\Controller;
use App\Repositories\UserRepository;
use Illuminate\Http\Request;
class SettingController extends Controller
{
protected $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function index(Request $request)
{
$users = $this->userRepository->getAll($request->all());
return view('backend.pages.users.index', compact('users'));
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.