Package Data | |
---|---|
Maintainer Username: | michaeltintiuc |
Maintainer Contact: | contact@michaeltintiuc.com (Michael Tintiuc) |
Package Create Date: | 2016-12-13 |
Package Last Update: | 2017-10-05 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-11 15:16:52 |
Package Statistics | |
---|---|
Total Downloads: | 34 |
Monthly Downloads: | 2 |
Daily Downloads: | 1 |
Total Stars: | 1 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 1 |
:bulb: Several starter interfaces and abstract classes for laravel projects
Require via composer
composer require michaeltintiuc/laravel-component
app/Components/
- holds all component dirs like Users, Posts, Tags, etc
app/Components/Users
- holds the model class (i.e. User) and all environment dirs like Admin, Site, etc
app/Components/Users/{ENV}
- holds all classes and routes.php
related to the environment specific implementation of a component
app/Components/Users/{ENV}/Requests
- holds form validation classes specific to an environment and component
namespace Acme\Components\Users\Admin;
use Illuminate\Http\Request;
use MichaelT\Component\Admin\ComponentController;
class UsersController extends ComponentController
{
public function __construct(Request $request, PostTagsRepo $repo)
{
parent::__construct($request, $repo);
$this->setComponent('user');
$this->setBaseView('admin.users');
$this->setSearchRoute('admin.users.index');
}
public function index(Request $request)
{
if ($request->has('search')) {
return $this->search($request->search);
}
$this->setTitle('All users');
$this->setHeading('Users list');
$users = $this->repo->all();
return $this->view('index')
->with(compact('users'));
}
...
}
namespace Acme\Components\Users\Admin;
use MichaelT\Component\Admin\Contracts\RepoContract;
use MichaelT\Component\Admin\Contracts\Searchable;
interface UsersRepoContract extends RepoContract, Searchable
{
}
namespace Acme\Components\Users\Admin;
use Acme\Components\Users\User;
use MichaelT\Component\Admin\ComponentRepo;
use Acme\Components\Users\Admin\UsersRepoContract;
class UsersRepo extends ComponentRepo implements UsersRepoContract
{
public function __construct(User $model)
{
parent::__construct($model);
$this->setComponent('user');
}
public function all()
{
return $this->model->get();
}
public function paginate()
{
return $this->model
->paginate($this->getPerPage());
}
public function find($id)
{
try {
return $this->model->findOrFail($id);
} catch (\Exception $e) {
throw new \FindAdminException($this->error('find'));
}
}
...
}
Route::group(['namespace' => 'Acme\Components\Users\Admin'], function () {
Route::resource('users', 'UsersController');
});
Route::group(['prefix' => 'admin', 'as' => 'admin.'], function () {
Route::group(['middleware' => ['auth']], function () {
require_once app_path().'/Components/Users/Admin/routes.php';
});
});
Contributions, bug-reports, feature and pull requests are always welcome!