SlideShare a Scribd company logo
1 of 42
Download to read offline
laravel-admin
Quick Create CRUD Application

Yehlu Huang

2017-08-19
About me
• 伍伍壹企業有限公司 www.551.com.tw

• 盟立電⼦子發票加值中⼼心 inv.551.com.tw

• 台中市企業經理理協進會 www.cpmat.org.tw

• 中華⺠民國汽⾞車車駕駛教育學會監事 www.drivingroc.org.tw

• ⼤大豐汽⾞車車駕駛⼈人訓練班 www.dfds.com.tw
Why PHP
• Free & Open

• Run Any environment

• Easy Learn

• Many Library & Framework
Why Laravel
• OOP

• PSR

• COMPOSER

• Package

• TDD

• https://coderseye.com/best-php-frameworks-for-web-
developers/
Laravel 5.4 Require
	 •	 PHP >= 5.6.4

	 •	 OpenSSL PHP Extension

	 •	 PDO PHP Extension

	 •	 Mbstring PHP Extension

	 •	 Tokenizer PHP Extension

	 •	 XML PHP Extension

• https://laravel.com/docs/5.4
Demo Environment
• user01~30.551.com.tw

• Account:tfc2017

• Password:laravel2017

• mysql Account:root Password:secret Host:127.0.0.1

• Ubuntu 16.04 + Docker 17.06.0-ce

• php-fpm PHP Version 7.0.21 + MariaDB 10.2.7
Laravel Project Foder
• ssh -l tfc2017 user01.551.com.tw

• /home/tfc2017/Sites/user01
Install Laravel
• cd ~/Sites

• composer create-project --prefer-dist laravel/laravel user01
Set the folder permissions
• cd user01

• chmod 777 storage -fR

• chmod 777 bootstrap/cache -fR
set up nginx host
• cd /home/tfc2017/Dockers/auto

• cp conf/user01.conf conf.d/

• docker-compose restart nginx
TEST
• http://user01.551.com.tw/
Create Database
• mysqladmin create user01 -u root -p -h 127.0.0.1
config .env
• vi .env

• DB_CONNECTION=mysql

• DB_HOST=127.0.0.1

• DB_PORT=3306

• DB_DATABASE=user01

• DB_USERNAME=root

• DB_PASSWORD=secret
Test DataBase
• php artisan migrate
Import SQL
• mysql user01 -u root -p -h 127.0.0.1 < ~/1.sql
Install laravel-admin
• composer require encore/laravel-admin "1.4.*"

• https://github.com/z-song/laravel-admin
Config laravel-admin
• vi config/app.php

• EncoreAdminProvidersAdminServiceProvider::class,

• php artisan vendor:publish --tag=laravel-admin

• php artisan admin:install
Test laravel-admin
• http://user01.551.com.tw/admin/

• Account:admin Password:admin
File structure
app/Admin

├── Controllers

│ ├── ExampleController.php

│ └── HomeController.php

├── bootstrap.php

└── routes.php
laravel-admin
Add Model Generator
• composer require reliese/laravel

• https://github.com/reliese/laravel
Config model Generator
• vi config/app.php

• RelieseCodersCodersServiceProvider::class,

// …
'providers' => [
/*
* Package Service Providers...
*/
RelieseCodersCodersServiceProvider::class,
],
// ...
Config model Generator
• php artisan vendor:publish --tag=reliese-models

• php artisan config:clear
Create Models
• php artisan code:models
Create Controller
• php artisan admin:make DepartmentController --
model=AppModelsDepartment

• // 在windows系统中

• php artisan admin:make DepartmentController —
model=AppModelsDepartment
Controller File
• /app/Admin/Controller/DepartmentController.php
Add Router
• app/Admin/routes.php

• $router->resource('/departments', DepartmentController::class);
Add Menu
• admin/auth/menu
Test
• http://user01.551.com.tw/admin/departments
Grid
• vi app/Admin/Controllers/DepartmentController.php

• http://z-song.github.io/laravel-admin/#/zh/model-grid-
column
Grid
$grid->column('department_id','ID')->sortable();

$grid->column('department_name','Department Name')->sortable();

$grid->column('department_manager_id','Manager')->sortable();

$grid->column('department_is_active','Active')->editable('select', [1 => 'Actived', 0 =>
'Disable'])->sortable();

$grid->actions(function ($actions) {

$actions->disableDelete();

//$actions->disableEdit();

});
Filter
$grid->filter(function ($filter) {

// 如果过滤器太多,可以使⽤用弹出模态框来显⽰示过滤器.

$filter->useModal();

$filter->like('department_name', 'Manager');

$filter->is('department_manager_id', 'Manager')-
>select(Employee::all()->pluck('emp_name', 'emp_id'));

$filter->is('department_is_active','Active')->select([1 =>
'Actived', 0 => 'Disable']);

});
Form
$form->display('id', 'ID');

$form->text('department_name','Department Name');

$form->select('department_manager_id', 'Manager')-
>options(Employee::all()->pluck('emp_name', 'emp_id'));

$form->switch('department_is_active', 'Active')->states(['Disable' => 0,
'Actived' => 1]);
Grid element
$grid->title()->editable('select', [1 => 'option1', 2 => 'option2', 3 => 'option3']);

$grid->status()->switch();
// 设置text、color、和存储值
$states = [
'on' => ['value' => 1, 'text' => '打开', 'color' => 'primary'],
'off' => ['value' => 2, 'text' => '关闭', 'color' => 'default'],
];
$grid->status()->switch($states);

$states = [
'on' => ['text' => 'YES'],
'off' => ['text' => 'NO'],
];
$grid->column('switch_group')->switchGroup([
'hot' => '热⻔门',
'new' => '最新'
'recommend' => '推荐',
], $states);

$grid->options()->select([
1 => 'Sed ut perspiciatis unde omni',
2 => 'voluptatem accusantium doloremque',
3 => 'dicta sunt explicabo',
4 => 'laudantium, totam rem aperiam',
]);

$grid->options()->radio([
1 => 'Sed ut perspiciatis unde omni',
2 => 'voluptatem accusantium doloremque',
3 => 'dicta sunt explicabo',
4 => 'laudantium, totam rem aperiam',
]);
Grid Screen
Filter Screen
Form Screen
Grid element
$grid->options()->checkbox([
1 => 'Sed ut perspiciatis unde omni',
2 => 'voluptatem accusantium doloremque',
3 => 'dicta sunt explicabo',
4 => 'laudantium, totam rem aperiam',
]);

$grid->picture()->image();
//设置服务器和宽⾼高
$grid->picture()->image('http://xxx.com', 100, 100);
// 显⽰示多图
$grid->pictures()->display(function ($pictures) {
return json_decode($pictures, true);
})->image('http://xxx.com', 100, 100);

$grid->name()->label();
//设置颜⾊色,默认`success`,可选`danger`、`warning`、`info`、`primary`、`default`、`success`
$grid->name()->label('danger');
// 接收数组
$grid->keywords()->label();

$grid->name()->badge();
//设置颜⾊色,默认`success`,可选`danger`、`warning`、`info`、`primary`、`default`、`success`
$grid->name()->badge('danger');
// 接收数组
$grid->keywords()->badge();

• http://z-song.github.io/laravel-admin/#/zh/model-grid
Form element
$form->text($column, [$label])->rules(‘required|min:10');
$form->select($column[, $label])->options([1 => 'foo', 2 => 'bar', 'val' => 'Option name’]);
$form->textarea($column[, $label])->rows(10);
$form->radio($column[, $label])->options(['m' => 'Female', 'f'=> ‘Male'])->default('m');
$form->checkbox($column[, $label])->options([1 => 'foo', 2 => 'bar', 'val' => 'Option name’]);
$form->email($column[, $label]);
$form->password($column[, $label]);
$form->mobile($column[, $label])->options(['mask' => '999 9999 9999’]);
$form->date($column[, $label])->format(‘YYYY-MM-DD');
$form->number($column[, $label]);
$form->editor($column[, $label]);
$form->hidden($column);
$form->slider($column[, $label])->options(['max' => 100, 'min' => 1, 'step' => 1, 'postfix' => 'years old’]);
$states = [
'on' => ['value' => 1, 'text' => '打开', 'color' => 'success'],
'off' => ['value' => 0, 'text' => '关闭', 'color' => 'danger'],
];
$form->switch($column[, $label])->states($states);
$form->display($column[, $label]);
$form->icon(‘icon');
• http://z-song.github.io/laravel-admin/#/zh/model-form
Learning Exercise
• zh-TW Language 

• Employee Controller

• Modify Grid

• Modify Form

• Add Images Upload (Field picture)
Thanks
• FaceBook : https://www.facebook.com/yehlu

• Line ID : yehlu

• Email:yehlu@551.com.tw

• Mobile telephone:0935-353-114

More Related Content

What's hot

Building Better Applications with Data::Manager
Building Better Applications with Data::ManagerBuilding Better Applications with Data::Manager
Building Better Applications with Data::Manager
Jay Shirley
 
Posts ‹ teslaecoenergy — word press php
Posts ‹ teslaecoenergy — word press phpPosts ‹ teslaecoenergy — word press php
Posts ‹ teslaecoenergy — word press php
Miroslav Miskovic
 

What's hot (16)

[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?
 
CodeIgniter L2 helper & libraries & form validation
CodeIgniter L2 helper & libraries & form validation CodeIgniter L2 helper & libraries & form validation
CodeIgniter L2 helper & libraries & form validation
 
Count to 10 and Say Yes
Count to 10 and Say YesCount to 10 and Say Yes
Count to 10 and Say Yes
 
Short lived immutable servers with masterless puppet
Short lived immutable servers with masterless puppetShort lived immutable servers with masterless puppet
Short lived immutable servers with masterless puppet
 
Building Better Applications with Data::Manager
Building Better Applications with Data::ManagerBuilding Better Applications with Data::Manager
Building Better Applications with Data::Manager
 
Fcr 2
Fcr 2Fcr 2
Fcr 2
 
Migrate yourself. code -> module -> mind
Migrate yourself. code -> module -> mindMigrate yourself. code -> module -> mind
Migrate yourself. code -> module -> mind
 
Turn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modulesTurn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modules
 
Posts ‹ teslaecoenergy — word press php
Posts ‹ teslaecoenergy — word press phpPosts ‹ teslaecoenergy — word press php
Posts ‹ teslaecoenergy — word press php
 
Build your own RESTful API with Laravel
Build your own RESTful API with LaravelBuild your own RESTful API with Laravel
Build your own RESTful API with Laravel
 
The journey of an (un)orthodox optimization
The journey of an (un)orthodox optimizationThe journey of an (un)orthodox optimization
The journey of an (un)orthodox optimization
 
Making and Breaking Web Services with Ruby
Making and Breaking Web Services with RubyMaking and Breaking Web Services with Ruby
Making and Breaking Web Services with Ruby
 
Building RESTful API
Building RESTful APIBuilding RESTful API
Building RESTful API
 
Let's write secure Drupal code! Drupal MountainCamp 2019
Let's write secure Drupal code! Drupal MountainCamp 2019Let's write secure Drupal code! Drupal MountainCamp 2019
Let's write secure Drupal code! Drupal MountainCamp 2019
 
Introduction to Zend framework
Introduction to Zend framework Introduction to Zend framework
Introduction to Zend framework
 
Django REST Framework における API 実装プラクティス | PyCon JP 2018
Django REST Framework における API 実装プラクティス | PyCon JP 2018Django REST Framework における API 実装プラクティス | PyCon JP 2018
Django REST Framework における API 実装プラクティス | PyCon JP 2018
 

Similar to Laravel admin20170819

10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
arcware
 
Writing extensible Word press-plugins
Writing extensible Word press-pluginsWriting extensible Word press-plugins
Writing extensible Word press-plugins
AllenSnook
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
elliando dias
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
patter
 

Similar to Laravel admin20170819 (20)

関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
 
Resource Routing in ExpressionEngine
Resource Routing in ExpressionEngineResource Routing in ExpressionEngine
Resource Routing in ExpressionEngine
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
 
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
 
Fatc
FatcFatc
Fatc
 
Drupal for ng_os
Drupal for ng_osDrupal for ng_os
Drupal for ng_os
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
 
Apostrophe (improved Paris edition)
Apostrophe (improved Paris edition)Apostrophe (improved Paris edition)
Apostrophe (improved Paris edition)
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4
 
Writing extensible Word press-plugins
Writing extensible Word press-pluginsWriting extensible Word press-plugins
Writing extensible Word press-plugins
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony Techniques
 
Practical PHP by example Jan Leth-Kjaer
Practical PHP by example   Jan Leth-KjaerPractical PHP by example   Jan Leth-Kjaer
Practical PHP by example Jan Leth-Kjaer
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
 
Zend framework: Getting to grips (ZF1)
Zend framework: Getting to grips (ZF1)Zend framework: Getting to grips (ZF1)
Zend framework: Getting to grips (ZF1)
 

Recently uploaded

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

Laravel admin20170819