PHP code example of erickfirmo / phpmodel

1. Go to this page and download the library: Download erickfirmo/phpmodel 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/ */

    

erickfirmo / phpmodel example snippets




 use ErickFirmo\Model;




  // Requires composer autoloader
  g a class for the entity
  class Car extends Model {
      
      protected $table = 'cars';
      
      protected $fillable = [
          'name',
          'company',
          'year',
          'plate',
          'color'
      ];
  }

  // Insert register example, returns boolean
  $saved = (new Car())->insert([
      'name' => $name,
      'company' => $company,
      'year' => $year,
      'plate' => $plate,
      'color' => $color,
  ]);
  
  // Select register example, returns collection
  $cars = (new Car())->select()
                     ->where('year', '=', $year)
                     ->get();




  // Returns all columns from `cars` table
  $cars = (new Car())->select()
                    ->get();




  // Returns specific columns from model table
  $cars = (new Car())->select(['name', 'company', 'year'])
                     ->get();




  $cars = (new Car())->select()
                     ->where('company', '=', $company)
                     ->get();




  $cars = (new Car())->select()
                     ->where('company', '=', $company)
                     ->where('year', '=', $year)
                     ->get();




  $saved = (new Car())->insert([
      'name' => $name,
      'company' => $company,
      'plate' => $plate,
      'year' => $year,
      'color' => $color,
  ]);




  $saved = (new Car())->update($id, [
            'plate' => $plate,
            'color' => $color,
        ]);




  $saved = (new Car())->delete($id);




  $car = (new Car())->findById($id);





  $cars = (new Car())->select()
                     ->orderBy('asc')
                     ->get();
                     


                   
  $cars = (new Car())->select()
                     ->orderBy('desc')
                     ->get();




  $cars = (new Car())->select()
                     ->limit(50)
                     ->get();




  $cars = (new Car())->select()
                    ->paginate(25);




<nav aria-label="Page navigation example">
    <ul class="pagination">
         foreach ($cars->pages as $key => $page) {