atlaschiew / laravel-study Goto Github PK
View Code? Open in Web Editor NEWhappy laraveling
happy laraveling
it is loaded by composer by providing Encore\Admin\AdminServiceProvider as provider in vendor\encore\laravel-admin\composer.json.
...
"extra": {
"laravel": {
"providers": [
"Encore\\Admin\\AdminServiceProvider"
],
...
for more information, please refer to https://laravel.com/docs/5.8/packages#package-discovery
网站设置
在 ROUTE_DOMAIN 不为空和 ROUTE_PREFIX 为空的情况下会触发 class "" not found (500 internal server error)
i hard code the solution in setCurrentUrl
method at vendor/dcat/laravel-admin/src/Widgets/Form.php.
grid
package (Encore\Admin\Grid) for this purpose.public function index
is default entry point of each controller or parent (adminController) one takes place if none implemented in derived controller. So let's look at parent's index method. public function index(Content $content)
{
return $content
->title($this->title())
->description($this->description['index'] ?? trans('admin.list'))
# derived class must implement protected function grid()
->body($this->grid());
}
grid
function of derived class. /**
* Make a grid builder.
*
* @return Grid
*/
protected function grid()
{
$grid = new Grid(new Article());
$grid->model()->ordered();
$grid->id('ID')->sortable();
$grid->title()->editable();
$grid->content()->editable();
$grid->picture()->image();
$grid->order()->orderable();
$grid->created_at();
$grid->updated_at();
return $grid;
}
in config/admin.php,
'route' => [
'prefix' => '',
'namespace' => 'App\\Admin\\Controllers',
'middleware' => ['web', 'admin', 'deny'],
],
# i wonder where is admin?
in app/Http/Kernel.php, i only have found both web (group) and deny (individual),
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
...
];
protected $routeMiddleware = [
...
'deny' => DenyRoutes::class,
];
The answer is in vendor/encore/laravel-admin/src/AdminServiceProvider.php, look for $middlewareGroups
.
based on sample from https://laravel-admin.org/docs/en/quick-start.
<?php
namespace App\Admin\Controllers;
use App\Models\User;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
class UserController extends AdminController
{
protected $title ='Users';
protected function grid()
{
$grid = new Grid(new User());
$grid->column('id', __('Id'));
$grid->column('name', __('Name'));
$grid->column('email', __('Email'));
$grid->column('password', __('Password'));
$grid->column('created_at', __('Created at'));
$grid->column('updated_at', __('Updated at'));
return $grid;
}
protected function detail($id)
{
$show = new Show(User::findOrFail($id));
$show->field('id', __('Id'));
$show->field('name', __('Name'));
$show->field('email', __('Email'));
$show->field('password', __('Password'));
$show->field('created_at', __('Created at'));
$show->field('updated_at', __('Updated at'));
return $show;
}
protected function form()
{
$form = new Form(new User());
$form->textarea('name', __('Name'));
$form->textarea('email', __('Email'));
$form->textarea('password', __('Password'));
return $form;
}
}
All methods on sample are protected, means they are not accessible by public, so we know the public methods are surely located in adminController. Let's open up adminController.
<?php
namespace Encore\Admin\Controllers;
use Encore\Admin\Layout\Content;
use Illuminate\Routing\Controller;
class AdminController extends Controller
{
use HasResourceActions;
/**
* Title for current resource.
*
* @var string
*/
protected $title = 'Title';
/**
* Set description for following 4 action pages.
*
* @var array
*/
protected $description = [
// 'index' => 'Index',
// 'show' => 'Show',
// 'edit' => 'Edit',
// 'create' => 'Create',
];
/**
* Get content title.
*
* @return string
*/
protected function title()
{
return $this->title;
}
/**
* Index interface.
*
* @param Content $content
*
* @return Content
*/
public function index(Content $content)
{
return $content
->title($this->title())
->description($this->description['index'] ?? trans('admin.list'))
->body($this->grid());
}
/**
* Show interface.
*
* @param mixed $id
* @param Content $content
*
* @return Content
*/
public function show($id, Content $content)
{
return $content
->title($this->title())
->description($this->description['show'] ?? trans('admin.show'))
->body($this->detail($id));
}
/**
* Edit interface.
*
* @param mixed $id
* @param Content $content
*
* @return Content
*/
public function edit($id, Content $content)
{
return $content
->title($this->title())
->description($this->description['edit'] ?? trans('admin.edit'))
->body($this->form()->edit($id));
}
/**
* Create interface.
*
* @param Content $content
*
* @return Content
*/
public function create(Content $content)
{
return $content
->title($this->title())
->description($this->description['create'] ?? trans('admin.create'))
->body($this->form());
}
}
We can see there are four public methods, index
, show
, edit
, and create
respectively.
index
build listing with use of grid object.show
build details of row.edit
build edit form.create
build add form.now open up parent class (https://github.com/z-song/laravel-admin/blob/v1.8.19/src/Controllers/HasResourceActions.php) and you will see there are another three new public methods, update
, store
& destroy
.
update
update existing record.store
add new record.destroy
delete a row.role administrator
is unremovable
...
cd madxframework
grep -rnw './' -e 'search keywords'
# search only on php files
grep -rnw './' -e 'search keywords' --include=*.php
cd madxframework
/usr/local/bin/ea-php82 ~/composer.phar update
# check latest composer.phar version in https://getcomposer.org/download/2.5.5/composer.phar
# then copy and run command below
cd ~
wget https://getcomposer.org/download/2.5.5/composer.phar
Tag reference is available in https://github.com/jqhph/dcat-admin/blob/2.0/src/Layout/Asset.php#L16
All views are parsed by the framework and placed in the storage directory. Think of these as the 'compiled' PHP files of your Blade code.
Also it's the views cache. So it doesn't have to parse every call
in this post, i will take Admin
facade as example.
# vendor/encore/laravel-admin/composer.json
"extra": {
"laravel": {
"providers": [
...
],
"aliases": {
"Admin": "Encore\\Admin\\Facades\\Admin"
}
}
}
shortly, app implement ArrayAccess, thus trigger app->make to produce a new Admin instance
i will explain in future. https://learnku.com/articles/37493.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.