PHP code example of moraesgil / api-restful-trait

1. Go to this page and download the library: Download moraesgil/api-restful-trait 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/ */

    

moraesgil / api-restful-trait example snippets


Route::resource('/samples', 'YourLaravelController', ['except' => ['create', 'edit', 'show']]);


use Traits\Controllers\ApiRestfulTrait;  //<<<<< add this line

class YourLaravelController extends Controller {
     use ApiRestfulTrait;  //<<<<< add this line  

     // ..others non-crud methods
}


use Traits\Entities\EntityValidatorTrait;  //<<<<< add this line

class YourLaravel extends Model {
   use EntityValidatorTrait; //<<<<< add this line
}


//in or controller you can pass
class YourLaravelController extends Controller {
   public function __construct()
   {  
      //Passing view and data
       $this->indexView = "youCrudBlade"; //default "crud"
       $this->indexData = [
          "pageTitle" => "Page title for exemple"
       ];

       // OR redirect to named route
       $this->indexRedirectRouteName ="myroute.indexpage"
   }
}

class YourLaravelController extends Controller {
   public function __construct(Mymodel $m)
   {
       $this->Model = $m;
       // or
       $this->modelName = "Mymodel";
       // or Just create a model same name of controller, from this controller sample "YourLaravel"
   }
}

class YourLaravelController extends Controller {
   public function __construct()
   {
       $this->modelGetMethodName = "myCustomPaginate";
   }
}
terminal
//terminal
php artisan make model YourLaravel