当前位置:网站首页>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 .
边栏推荐
- The consciousness of a programmer
- 基于Cortex-M3、M4的精准延时(系统定时器SysTick延时,可用于STM32、ADuCM4050等)
- Immutable learning road -- farewell to traditional copy
- How to apply for software
- 《牛客刷verilog》Part I Verilog快速入门
- Startup mode of SoC verification environment
- JS call() and apply()
- After the newly assigned variable of the applet is modified, the original variable will also be modified
- Machine learning deep learning -- Vectorization
- SOC验证环境的启动方式
猜你喜欢

电脑的dwg文件怎么打开

【图像融合】基于matlab方向离散余弦变换和主成分分析图像融合【含Matlab源码 1907期】

ROS2/DDS/QoS/主题的记录

Wechat applet new version prompt update

Records of ros2/dds/qos/ topics

第九章 APP项目测试(2) 测试工具

great! Auto like, I use pyautogui!

What if the desktop computer is not connected to WiFi

Machine learning deep learning -- Vectorization

php开发支付宝支付功能之扫码支付流程图
随机推荐
The print area becomes smaller after epplus copies the template
小白一键重装官网下载使用方法
计算学生成绩等级(虚函数和多态)
固态硬盘开盘数据恢复的方法
30岁了开始自学编程,家里比较困难还来得及吗?
My IC journey - the growth of senior chip design verification engineers - "Hu" said that IC engineers are perfect and advanced
本轮压力测试下,DeFi协议们表现如何?
What if the desktop computer is not connected to WiFi
Sleep more, you can lose weight. According to the latest research from the University of Chicago, sleeping more than 1 hour a day is equivalent to eating less than one fried chicken leg
Successfully solved: selenium common. exceptions. TimeoutException: Message: timeout: Timed out receiving message from
Upgrade PHP to php7 X (III) failure of wechat payment callback
Upgrade PHP to php7 The impact of X (I). The problem of session retention. Keep login
Cannot import name 'escape' from 'jinja2' [solved successfully]
【Flink】RocksDB增量模式checkpoint大小持续增长的问题及解决
Codeforces Round #802 (Div. 2) C D
great! Auto like, I use pyautogui!
执行SQL响应比较慢,你有哪些排查思路?
Record of the 25th week
Response (XI)
Penetration test - directory traversal vulnerability