1. Go to this page and download the library: Download clock-it/base 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/ */
clock-it / base example snippets
namespace App\Providers;
use App\DataSources\MRoles\Repositories\MRoleRepository;
use App\DataSources\MRoles\Interfaces\MRoleRepositoryInterface;
use App\DataSources\TUsers\Repositories\TUserRepository;
use App\DataSources\TUsers\Interfaces\TUserRepositoryInterface;
use Illuminate\Support\ServiceProvider;
class RepositoryServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->bind(
TUserRepositoryInterface::class,
TUserRepository::class
);
$this->app->bind(
MRoleRepositoryInterface::class,
MRoleRepository::class
);
}
}
namespace App\DataSources\TUsers\Repositories;
use Clock\Baserepo\Repositories\BaseRepository;
use App\DataSources\TUsers\TUser;
use App\DataSources\TUsers\Interfaces\TUserRepositoryInterface;
class TUserRepository extends BaseRepository implements TUserRepositoryInterface
{
/**
* TUserRepository constructor.
*
* @param TUser $tUser
*/
public function __construct(TUser $tUser)
{
parent::__construct($tUser);
$this->model = $tUser;
}
/**
* ユーザーリスト取得
*
* @param array $columns
* @param int $limit
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|mixed
*/
public function getUserList($columns = ['*'], int $limit = 15)
{
return $this->model->with('roles')->select($columns)->paginate($limit);
}
/**
* アカウント作成
*
* @param array $params
* @return TUser
* @throws \Exception
*/
public function createAccount(array $params) : TUser
{
try {
$data = collect($params)->except('password')->all();
$tUser = new TUser($data);
$tUser->password = bcrypt($params['password']);
$tUser->save();
return $tUser;
} catch (\Exception $e) {
throw new \Exception($e->getMessage(), 500, $e);
}
}
}
namespace App\Http\Controllers;
use Illuminate\Http\RedirectResponse;
use App\DataSources\TUsers\Requests\CreateTUserRequest;
use App\DataSources\TUsers\Interfaces\TUserRepositoryInterface;
class UserController extends Controller
{
/**
* @var
*/
private $tUserRepo;
/**
* UserController constructor.
*
* @param TUserRepositoryInterface $tUserRepo
*/
public function __construct(TUserRepositoryInterface $tUserRepo)
{
$this->middleware('auth');
$this->tUserRepo = $tUserRepo;
}
/**
* アカウント管理
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index()
{
$users = $this->tUserRepo->getUserList();
return view('user.index', [
'users' => $users,
]);
}
/**
* アカウント登録
*
* @param CreateTUserRequest $request
* @return RedirectResponse
*/
public function store(CreateTUserRequest $request) : RedirectResponse
{
$this->tUserRepo->createAccount($request->except('_method', '_token'));
session()->flash('status', __('アカウント登録が完了しました'));
return redirect()->route('users.index');
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.