PHP code example of engency / resource-controllers
1. Go to this page and download the library: Download engency/resource-controllers 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/ */
engency / resource-controllers example snippets
use Illuminate\Http\Request;
use Engency\Http\Controllers\ResourceController;
use Engency\Http\Controllers\DefaultResourceActions;
class UserController extends ResourceController
{
use DefaultResourceActions;
/**
* Provide the resource class in the parent's constructor.
* Add any middleware to authorize users.
*/
public function __construct()
{
parent::__construct(User::class);
$this->middelware('auth');
}
/**
* Set the scope for this resource controller.
* The expected return value should either be a query builder or a Laravel collection.
*
* @param Request $request
* @return \Illuminate\Database\Query\Builder|\Illuminate\Support\Collection|\Illuminate\Database\Query\Builder
*/
protected function getScope(Request $request)
{
return User::query();
}
}
use \Illuminate\Database\Eloquent\Model;
use \Engency\ModelValidation\Validatable;
use Engency\DataStructures\CustomDataFormats;
use Engency\DataStructures\ExportsCustomDataFormats;
class User extends Model implements ExportsCustomDataFormats
{
use Validatable; // trait ats on;
* https://github.com/Engency/eloquent-formatting
*/
protected $exports = [
'default' => [
'name',
],
'complete' => [
'name',
'email'
]
];
/**
* Basic validation for resource attributes.
* Visit complete documentation on model validation on;
* https://github.com/Engency/laravel-model-validation
*/
public function rules() : array {
return [
'name' => '
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.