1. Go to this page and download the library: Download radfic/gastropod 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/ */
radfic / gastropod example snippets
public function boot()
{
$this->routes(function () {
/** [... YOUR OTHER ROUTE GROUPS: web, api, ecc ..] */
//G@STROPOD ROUTES->copy in your RouteServiceProvider
Route::prefix('gastropod')
->middleware('web')
->namespace($this->namespace)
->group(base_path('routes/gastropod.php'));
//END of G@STROPOD ROUTES
});
}
namespace App\Http\Controllers\Gastropod;
use RadFic\Gastropod\Http\Controllers\GastropodCrudController;
/** We need to import the models we will need later on. */
use App\Models\User;
/**
* GastropodUserController
*
* It must extend RadFic\Gastropod\Http\Controllers\GastropodCrudController.
*/
class GastropodUserController extends GastropodCrudController
{
/**
* In the constructor we do all needed configuration for the resource crud.
*/
public function __construct()
{
/**
* The Eloquent model we want to crud.
*/
$model = User::class;
/**
* Relations map is a map of all relations we want our crud to take care of.
* `key` is the name of the field holding reference to the other class id.
* `field` is the name of the field we want to show in our crud from the related table.
* `model` is the Eloquent model of the referenced table.
*/
$relationsMap = [
/**
* We define this default relationship using gastropod_admins
* table's `user` relationship.
*/
/* Example:
'profile' => [
'key' => "profile_id",
'field' => 'name',
'model' => Profile::class //always remember to import the other model as well, using `use`
]
*/
];
/**
* After setup we call GastropodCrudController's constructor
* to take care of the init job.
*/
parent::__construct($model,$relationsMap);
}
}
/** resource routes */
Route::resources([
/**
* gastropod_admins is installed by default: it manages the crud admin permissions on app users.
*/
'gastropod_admins' => 'RadFic\Gastropod\Http\Controllers\GastropodAdminController',
/** Our brand new resource: Users */
'users' => 'App\Http\Controllers\Gastropod\GastropodUserController',
]);
php artisan gastropod:install
php artisan migrate
sql
INSERT INTO `gastropod_admins` (`user_id`) VALUES (USER-ID-TO-MAKE-ADMIN);
php artisan make:gastropodController Gastropod\GastropodUserController User
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.