laravel-репозиторий
Адрес склада на Github
Адрес Документа Репозитория
Очистить структуру каталогов
Модели отвечают только за определение моделей(например, ассоциация моделей, область действия, get, атрибут набора и т.д.)
Репозиторий обрабатывает эту таблицу Со всей соответствующей бизнес-логикой, а не просто вводит модели, любой кэш, связанный с redis, может быть введен, и код может быть быстро найден
Контроллеры отвечают только за обработку простой логики и извлечение данных пересылки. Он должен быть простым и чистым От
Апп
Http
Контроллер
Администратор
- Индексконтроллер
- Пользовательский контроллер
- Контроллер конфигурации
- …
Запрос (все классы проверки запроса)
Администратор
Индекс
- Запрос на хранение
- Запрос на обновление
- Запрос на уничтожение
Пользователь
- …
Конфиг
- …
- Запрос. php
Модели (все модели моделей)
Пользователь (все модели, связанные с пользователем)
- Пользователь (все модели, связанные с пользователем)
- Пользователь (все модели, связанные с пользователем)
- Пользователь (все модели, связанные с пользователем)
Конфиг
- Конфиг
- …
- Конфиг
Хранилища
Пользователь (все склады, связанные с пользователем)
- Пользователь (все склады, связанные с пользователем)
- Пользователь (все склады, связанные с пользователем)
- Пользователь (все склады, связанные с пользователем)
- …
Установка и использование
composer require littlebug/laravel-repository mkdir app/Http/Requests # Create your own Request validation base class # Like the following file
Примерно Один Код Генерации Ключа
# After injecting commands into your laravel project
# Input
php artisan list
# If you see the following tips, you can start generating code quickly!~
core
Core: controller generates Controller
{--table=} Specifies the name of the table [Specifies that this parameter generates a view file from the table]
{Name=} Specifies that the name can be namespace [-- name = Home / IndexController or Home\ IndexController]
{- r=} Specifies that Repository needs to start from the Repositories directory; the default is to use the same name Repository as the controller
{- request=} specifies the request directory; needs to start from the Requests directory; defaults to the controller namespace
{- pk=} Specifies the primary key name, default ID
Core: generate generates controller | model | repository | request | views
{- table=} Specifies the name of the table [supports the specified database, such as log. crontabs]
{- path=} specifies the directory [no absolute path is passed, otherwise relative paths are used starting with app/Models]
Default Generation of Model Name Using Table Name Generation
core:model# Let's have a try.
# Generate code at the prompt of commands help document
# If your project uses database prefix, don't forget to add it in database. php, otherwise you won't find table.
# Take a chestnut, for example, the member_message table
php artisan core:generate --table=member_message --path=Member --controller=Member/MemberMessageController
# In the terminal you can see the following results
The file [/Users/wanchao/www/lara-test/app/Models/Member/MemberMessage.php] was successfully generated
The file [/Users/wanchao/www/lara-test/app/Repositories/Member/MemberMessageRepository.php] was successfully generated
The file [/Users/wanchao/www/lara-test/app/Http/Requests/Member/MemberMessage/UpdateRequest.php] was successfully generated
The file [/Users/wanchao/www/lara-test/app/Http/Requests/Member/MemberMessage/DestroyRequest.php] was successfully generated
The file [/Users/wanchao/www/lara-test/app/Http/Requests/Member/MemberMessage/StoreRequest.php] was successfully generated
# Add Routes/web.php
Route::group(['namespace' => 'Member','prefix' => 'member'], function ($route) {
$route->get('index', '[email protected]');
$route->get('message', '[email protected]');
});
### Modify MemberMessage Controller
### DD Prints Data in EmberMessage Controller
public function index()
{
$filters = Helper::filter_array(request()->all());
$filters['order'] = 'id desc';
$list = $this->memberMessageRepository->paginate($filters);
dd($list);
}
# Terminal
php artisan serve
vist localhost:8001/member/message
# Instead of mechanically copying and pasting my chestnuts, you should try some tables that exist in your database.традиция
# Maybe you want to customize your own Repository # Create a Repository. PHP in app Repository # Extension and partial rewriting of it, such as success and error methods, can be changed to the data format you like.
Разработанный в этом режиме, структура проекта очень понятна, использование репозитория лаконично до взрывоопасности, требуется всего несколько минут, чтобы ознакомиться с его инструкциями, вам понравится (vi)
Репозиторий использует документы