当前位置:网站首页>Laravel's little knowledge
Laravel's little knowledge
2022-06-25 04:52:00 【Kiway.】
Laravel Little knowledge
Laravel structure

Frequent operations often occur in these places
Model :app\Model
controller :app\Http
View :resources\views
route :routes
The extension methods are vendor Folder
Composer Use
Composer install / to update
composer install
composer update
Composer It is mainly used to download and add extensions
for example :
composer require mews/captcha
composer require Jpush/Jpush
database
PHP Grammatical uniformity , Database access will be somewhat different , More examples are needed , practice .
The link below is Laravel 5.7 Development documentation for , To understand the syntax of its docking database .
Laravel 5.7
route
Routing is Laravel Used to specify which method of an interface method in which file .
for example :
Route::get('equipmentmodel', '[email protected]');
Route::post('equipment/white', '[email protected]');
controller
The controller is the main logic code , There are methods corresponding to each function , And then call model To perform database operations .
<?php
namespace App\Http\Controllers;
use App\Lib\Redis;
class EquipmentController extends BaseController{
public function __construct() {
parent::__construct ();
$this->equipment = new \App\Lib\Equipment();
}
// list
function index(){
// Create a business class object ( Related... Has been associated in the constructor of the business object model class )
$equipment = $this->equipment;
// Filter title , After assignment here ,model Through the business class object, you can get
$equipment->search['title'] = $this->request->input('title','');
$equipment->search['start'] = $this->request->input('start','')
$firmware = new \App\Lib\Firmware();
$this->_Result['firmware'] = $firmware->getModel()->getFirmware();
$model = new \App\Lib\EquipmentModel();
// The form needs to be backfilled when returning from the edit page
$this->_Result['param'] = $equipment->search;
if( $this->request->input('isexport','')==1){
return $this->export($equipment->search);
}
// Button for automatic locking configuration
$is_auto=$this->equipment->getModel()->simpleGetRow();
$this->_Result['is_auto']=$is_auto['is_auto'];
// Basic usage , This usage will associate the list class by the name of the business class
$this->_Result['pagelistting'] = $equipment->createPageListting('pagelistting',site_url('admin/equipment?type='. $equipment->search['type']),true)->ajaxOutPut();
return view('equipment/equipmentpagelist',$this->_Result);
}
// modify
public function edit(){
}
/** * Delete */
public function del() {
}
/* * gcc */
public function substrSerialNumber($number)
{
}
public function detail(){
}
}
Model
model The method is directly related to the database statement operation , Add, delete, modify and query are performed here .
<?php
namespace App\Model;
use Qusu\Lib\Core\DBModel;
class AdvertModel extends DBModel\DBModel{
/** * The data table associated with the model * * @var string */
protected $table = 'dlc_advert';
protected $primaryKey='id';
protected $created_at='createtime';
protected $updated_at='updatetime';
public function listingData(\Qusu\Lib\Core\Listing $listing){
$libobj = $listing->getContext();
$db = \DB::table($this->getFullTableName());
$db->select ( \DB::raw($this->getFullFieldName('*')) );
$query = $db->get();
return $this->getArray($query);
}
public function pageListingData(\App\Lib\Listing\AdvertPageListing $listing){
$libobj = $listing->getContext();
$db = \DB::table($this->getFullTableName());
$db->select ( \DB::raw('SQL_CALC_FOUND_ROWS '.$this->getFullFieldName('*')) )
->where('is_del','=',0)
->orderby('weight','desc');
if(isset($libobj->search) && getvalue($libobj->search, 'title')!=''){
$db->where($this->getFullFieldName('chinaTitle'),'like','%'.getvalue($libobj->search, 'title').'%');
$db->orwhere($this->getFullFieldName('franceTitle'),'like','%'.getvalue($libobj->search, 'title').'%');
$db->orwhere($this->getFullFieldName('koreaTitle'),'like','%'.getvalue($libobj->search, 'title').'%');
$offset = $listing->getOffset();
$limit = $listing->getCustomLimit();
if ($limit !== 0) {
$db->offset($offset)->limit ( $limit );
}
$query = $db->get();
return $this->getTotalList($query);
}
public function detail(\App\Lib\Advert $lib){
$db = \DB::table($this->getFullTableName());
$db->select ( \DB::raw('SQL_CALC_FOUND_ROWS '.$this->getFullFieldName('*')) );
$db->where($this->getFullFieldName('id'),'=',$lib->getId());
$data = $db->first();
if(!empty($data)){
return get_object_vars($data);
}
return array();
}
public static function adReleaseNum()
{
return self::where(['is_del'=>0,'is_show'=>1])->count();
}
}
Laravel Framework of the MVC The model is easy to use , If you want to know more, you need to practice and understand more .
边栏推荐
- Construction scheme of distributed websocket
- Why is the TCP handshake just 3 times?
- 魔法猪系统重装大师怎么使用
- win11蓝牙无法连接怎么办?win11蓝牙无法连接的解决方法
- How PHP gets the user's City
- File upload vulnerability shooting range upload labs learning (pass1-pass5)
- Penetration test - directory traversal vulnerability
- 渗透测试-目录遍历漏洞
- dotnet-exec 0.4.0 released
- Why PHP is not safe
猜你喜欢

Difference between asemi high power FET and triode
Triangle class (construction and deconstruction)

The solution of wechat applet switchtab unable to take parameters
![[untitled]](/img/68/5e711f7c473dcea54a56f7b7e48604.png)
[untitled]

领导:谁再用 Redis 过期监听实现关闭订单,立马滚蛋!

Region of Halcon: generation of multiple regions (3)

Efficient NoSQL database service Amazon dynamodb experience sharing

php开发支付宝支付功能之扫码支付流程图

EL & JSTL (XIII)

JS' sort() function
随机推荐
ORA-00800: soft external error
Méthode de récupération des données d'ouverture du disque dur à l'état solide
ASEMI三相整流桥的工作原理
OOP 向量加减(友元+拷贝构造)
Leader: who can use redis expired monitoring to close orders and get out of here!
Method of opening data recovery of solid state disk
CTF_ Web: Changan cup-2021 old but a little new & asuka
三角形类(构造与析构)
我的IC之旅——资深芯片设计验证工程师成长——“胡”说IC工程师完美进阶
固态硬盘开盘数据恢复的方法
cannot import name ‘escape’ from ‘jinja2’【成功解决】
渗透测试-目录遍历漏洞
2.0springmvc uses restful
Web3 DApp用户体验最佳实践
Cannot import name 'escape' from 'jinja2' [solved successfully]
Record of the 25th week
Vscode 设置clang-format
OOP栈类模板(模板+DS)
Immutable學習之路----告別傳統拷貝
Integrate CDN to create the ultimate service experience for customers!