当前位置:网站首页>Laravel's little knowledge

Laravel's little knowledge

2022-06-25 04:52:00 Kiway.

Laravel structure

 This is a Laravel The folder structure of
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 .

原网站

版权声明
本文为[Kiway.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202210533123539.html