当前位置:网站首页>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 .
边栏推荐
- EL & JSTL (XIII)
- Precise delay based on Cortex-M3 and M4 (systick delay of system timer can be used for STM32, aducm4050, etc.)
- cannot import name ‘escape’ from ‘jinja2’【成功解决】
- JDBC (IV)
- 领导:谁再用 Redis 过期监听实现关闭订单,立马滚蛋!
- 三角形类(构造与析构)
- File upload vulnerability shooting range upload labs learning (pass1-pass5)
- Student achievement management system based on SSH
- Php7.2 add JPEG extension
- leetcode1221. Split balance string
猜你喜欢

leetcode1221. 分割平衡字符串

Code scanning payment flow chart of Alipay payment function developed by PHP

buuctf(pwn)

2.0springmvc uses restful

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

为什么TCP握手刚刚好是3次呢?

Kotlin Compose 完善toDo项目 Surface 渲染背景 与阴影

30岁了开始自学编程,家里比较困难还来得及吗?

《牛客刷verilog》Part I Verilog快速入门

The SQL response is slow. What are your troubleshooting ideas?
随机推荐
Use text analysis to identify the main gender in a text
Kotlin Compose 完善toDo项目 Surface 渲染背景 与阴影
Deep learning - several types of learning
dotnet-exec 0.4.0 released
buuctf web
JS arguments
OpenSea PHP开发包
[Flink] problems and solutions of the continuous growth of checkpoint size in rocksdb incremental mode
515. find the maximum value / Sword finger offer II 095 in each tree row Longest common subsequence
The consciousness of a programmer
Calculate student grade (virtual function and polymorphism)
【FLink】access closed classloader classloader.check-leaked-classloader
Why PHP is not safe
Integrate CDN to create the ultimate service experience for customers!
Which programming language is the most cumbersome to implement Hello world?
《QDebug 2022年6月》
JDBC (IV)
Successfully solved: selenium common. exceptions. TimeoutException: Message: timeout: Timed out receiving message from
大话云原生数据库中的存算分离
Precise delay based on Cortex-M3 and M4 (systick delay of system timer can be used for STM32, aducm4050, etc.)