1. Go to this page and download the library: Download wendelladriel/laravel-more 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/ */
wendelladriel / laravel-more example snippets
namespace App\Repositories;
use App\Models\User;
use WendellAdriel\LaravelMore\BaseRepository;
class UserRepository extends BaseRepository
{
/**
* @param User $user
*/
public function __construct(User $user)
{
parent::__construct($user);
}
}
/**
* Gets all models
*
* @param array $columns
* @return Collection
*/
public function getAll(array $columns = self::ALL_COLUMNS): Collection
// GET ALL RECORDS WITH ALL COLUMNS
$this->userRepository->getAll();
// GET ALL RECORDS WITH SPECIFIC COLUMNS
$this->userRepository->getAll(['id', 'email']);
/**
* Gets all models by the given attribute
*
* @param string $attribute
* @param mixed $value
* @param string $compareType
* @param bool $withTrash
* @return Collection
*/
public function getAllBy(string $attribute, $value, string $compareType = '=', bool $withTrash = false): Collection
/**
* Gets a model by the given attribute or throws an exception
*
* @param string $attribute
* @param mixed $value
* @param string $compareType
* @param bool $withTrash
* @return Model
*/
public function getByOrFail(string $attribute, $value, string $compareType = '=', bool $withTrash = false): Model
/**
* Gets a model by some attributes or throws an exception
*
* @param array $params
* @param string $compareType
* @param bool $withTrash
* @return Model
*/
public function getByParamsOrFail(array $params, string $compareType = '=', bool $withTrash = false): Model
/**
* Updates one or more models
*
* @param string $attribute
* @param $value
* @param array $updateFields
* @return int
*/
public function updateBy(string $attribute, $value, array $updateFields): int
// UPDATE SINGLE RECORD
$this->userRepository->updateBy('id', 1, ['email' => '[email protected]']);
// UPDATE MULTIPLE RECORDS
$this->userRepository->updateBy('type', ['owner', 'manager'], ['is_active' => true]);
/**
* Deletes one or more models
*
* @param string $attribute
* @param $value
* @return mixed
*/
public function deleteBy(string $attribute, $value)
// DELETE SINGLE RECORD
$this->userRepository->deleteBy('id', 1);
// DELETE MULTIPLE RECORDS
$this->userRepository->deleteBy('type', ['owner', 'manager']);
/**
* Creates a new model
*
* @param array $args
* @return Builder|Model
*/
public function create(array $args)
/**
* Disables a named global scope
*
* @param string $scopeName
* @return BaseRepository
*/
public function disableGlobalScope(string $scopeName): BaseRepository
/**
* Enables a named global scope
*
* @param string $scopeName
* @return BaseRepository
*/
public function enableGlobalScope(string $scopeName): BaseRepository