PHP code example of asb / morphmtm

1. Go to this page and download the library: Download asb/morphmtm library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

asb / morphmtm example snippets


    php artisan mtm:build category
    

    What is the Model Name [Category]:
    >[enter]
     What is the Model Plural Name [categories]:
    >[enter]
    What is the Model Relation Name [categoryable]:
    >categorizable //Here the default name of the relationship is not good, and we changed it.
    
  
    //The class model has+yourModelName
    

  getModelsHave(string|ID $MTMmodel)
  

  getCategories(Model $model)
  

  hasCategries(string|ID $model,string $MTMmodel)
  

  assignCategory(Model $model,string|ID $MTMmodel)
  

  addCategory(Model $model,string|ID $MTMmodel)
  

  updateCategory(Model $model,string|ID $MTMmodel,string|ID $newMTMmodel)
  

  removeCategory(Model $model,string|ID $MTMmodel)
  

  removeAllCategory(Model $model)
  
    
    createCategoryModel(string $MTMmodel)
    
    
    getAllCategoryModel(bool $onlyTrashed=false)
     

     getCategoryModel(string|ID $MTMmodel)
    
 
    updateCategoryModel(string|ID $MTMmodel, string $update_Category):
    

     removeCategoryModel(string|ID $MTMmodel) 
    

     restoreCategoryModel(string|ID $MTMmodel) 
    
`clickhouse
    php artisan vendor:publish --tag=morph-mtm-config