PHP code example of michaeltintiuc / laravel-component
1. Go to this page and download the library: Download michaeltintiuc/laravel-component 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/ */
michaeltintiuc / laravel-component example snippets
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 () {
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.