当前位置:网站首页>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 .
边栏推荐
- Precise delay based on Cortex-M3 and M4 (systick delay of system timer can be used for STM32, aducm4050, etc.)
- parallel recovery slave next change & parallel recovery push change
- 我的IC之旅——资深芯片设计验证工程师成长——“胡”说IC工程师完美进阶
- 高效的NoSQL数据库服务Amozon DynamoDB体验分享
- 重磅直播 | 相移法+多频外差之数学原理推导+实现
- "Daily practice, happy water" 1108 IP address invalidation
- 固态硬盘开盘数据恢复的方法
- What if win11 Bluetooth fails to connect? Solution of win11 Bluetooth unable to connect
- Join() in JSZ
- 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
猜你喜欢

绝了!自动点赞,我用 PyAutoGUI!

Chapter IX app project test (2) test tools

great! Auto like, I use pyautogui!

Introduction to the hardest core PWN in the whole network_ Graphic analysis
![[image fusion] image fusion based on MATLAB directional discrete cosine transform and principal component analysis [including Matlab source code 1907]](/img/a1/f7a35a04e180e89d7f2fdbf89c1160.jpg)
[image fusion] image fusion based on MATLAB directional discrete cosine transform and principal component analysis [including Matlab source code 1907]

EL & JSTL (XIII)

leetcode1221. 分割平衡字符串

buuctf web

Record the problem of C # print size once

30岁了开始自学编程,家里比较困难还来得及吗?
随机推荐
ThinkPHP 5 log management
Upgrade PHP to php7 The impact of X (2), the obsolescence of mcrypt decryption
2.0springmvc uses restful
ASEMI大功率场效应管和三极管的区别
ORA-00800: soft external error
DMA double buffer mode of stm32
魔法猪系统重装大师怎么使用
olap分析引擎——Kylin4.0
Vscade setting clang format
Huawei Hongmeng development lesson 4
Working principle of asemi three-phase rectifier bridge
Immutable學習之路----告別傳統拷貝
php开发支付宝支付功能之扫码支付流程图
高效的NoSQL数据库服务Amozon DynamoDB体验分享
Kotlin Compose 监听软键盘 点击enter提交事件
绝了!自动点赞,我用 PyAutoGUI!
Why is the TCP handshake just 3 times?
重磅直播 | 相移法+多频外差之数学原理推导+实现
Machine learning deep learning -- Vectorization
The solution of wechat applet switchtab unable to take parameters