Simple CRUD creation package for Laravel.
- composer install ottiem/cruddy
- php artisan vendor:publish
- adjust any settings in the newly created config/cruddy.php file
- add the cruddy connection to all migrations that create the table you want to turn into a basic CRUD resource:
Schema::connection('cruddy')
When you run php artisan vendor:publish
it will create a config file for you in config/cruddy.php. This is where you can set all your CRUD settings and options. For example, the needs_ui
variable within config/cruddy.php controls whether to create the frontend view files or not. If you are making an API that does not require a frontend, then you should set this value to false so that the view files will not be created.
To set the database connection correctly before running the migrations, the APP_ENV
variable within your .env file cannot be set to testing
or local
.
// Within config/cruddy.php, we can control the creation of the frontend view files like so:
'needs_ui' => false,
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateFooTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::connection('cruddy')->create('foos', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('bar');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('foos');
}
}
If these files do not already exist, then they will be created from running the example above. Files will not be overwritten if they already exist.
- app/Http/Controllers/FooController.php
- app/Models/Foo.php
- app/Http/Requests/StoreFoo.php
- app/Http/Requests/UpdateFoo.php
- resources/views/foo/create.blade.php
- resources/views/foo/edit.blade.php
- resources/views/foo/index.blade.php
- resources/views/foo/show.blade.php
This will be added to your routes/web.php file for the example above:
// Foo Resource
Route::resource('foos', 'App\Http\Controllers\FooController');