Be warned: This is a work in progress. Nothing actually works yet!
Add nils-werner/scaffold
as a requirement to composer.json:
{
"require": {
"nils-werner/scaffold": "dev-master"
},
"repositories": [
{
"type":"vcs",
"url":"https://github.com/nils-werner/laravel-scaffold"
}
]
}
Then run composer update
or composer install
Next step is to tell laravel to load the serviceprovider. In app/config/app.php
add
// ...
'NilsWerner\Scaffold\ScaffoldServiceProvider'
// ...
to the providers
array.
Most of the code here is just a package wrapper so the important components don't have to be in /app
:
routes.php
controllers/ScaffoldController.php
views/*.blade.php
It's in ScaffoldController
where most of the magic happens:
- Deduct the model name from the URL and see if it exists
- Fetch the schema of the table associated with the model
- Process and display the data and the schema in a table or a form
Each Model
can configure an array of columns and fields it wants to show in the scaffolding view:
public $columns = ['realname'];
public $fields = ['realname', 'email'];
Additionally, you can use Eloquent ORM getters and setters to manipulate the input received from the form, i.e. Hash::make()
a password when saving and only display "****" when editing:
public function setPasswordAttribute($value)
{
if($value != "****")
$this->attributes['password'] = Hash::make($value);
}
public function getPasswordAttribute($value)
{
return "****";
}