PHP code example of achillesp / laravel-crud-forms

1. Go to this page and download the library: Download achillesp/laravel-crud-forms 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/ */

    

achillesp / laravel-crud-forms example snippets


use App\Models\Post;
use Achillesp\CrudForms\CrudForms;

class PostController extends Controller
{
    use CrudForms;

    public function __construct(Post $post)
    {
        $this->model = $post;

        $this->formFields = [
            ['name' => 'title',       'label' => 'Title',    'type' => 'text'],
            ['name' => 'body',        'label' => 'Body',     'type' => 'textarea'],
            ['name' => 'category_id', 'label' => 'Category', 'type' => 'select', 'relationship' => 'category'],
        ];
    }
}

// routes/web.php
Route::resource('posts', PostController::class);

use App\Http\Controllers\PostController;

Route::resource('posts', PostController::class);

use App\Models\Post;
use Achillesp\CrudForms\CrudForms;

class PostController extends Controller
{
    use CrudForms;

    public function __construct(Post $post)
    {
        $this->model = $post;
    }
}

$this->formFields = [
    ['name' => 'title', 'label' => 'Title', 'type' => 'text'],
    ['name' => 'slug', 'label' => 'Slug', 'type' => 'text'],
    ['name' => 'body', 'label' => 'Enter your content here', 'type' => 'textarea'],
    ['name' => 'publish_on', 'label' => 'Publish Date', 'type' => 'date'],
    ['name' => 'published', 'label' => 'Published', 'type' => 'checkbox'],
    ['name' => 'category_id', 'label' => 'Category', 'type' => 'select', 'relationship' => 'category'],
    ['name' => 'tags', 'label' => 'Tags', 'type' => 'select_multiple', 'relationship' => 'tags'],
];

$this->indexFields = ['title', 'category_id', 'published'];

$this->withTrashed = true;

Route::put('posts/{post}/restore', [PostController::class, 'restore'])->name('posts.restore');

$this->validationRules = [
    'title'       => 'dy'        => '  'category_id' => '

$this->validationMessages = [
    'body.

$this->validationAttributes = [
    'title' => 'Post title'
];

// config/crud-forms.php
'theme' => 'tailwind', // or 'bootstrap' (default)

php artisan vendor:publish --provider="Achillesp\CrudForms\CrudFormsServiceProvider" --tag=config

php artisan vendor:publish --provider="Achillesp\CrudForms\CrudFormsServiceProvider" --tag=config

# Bootstrap 3 views
php artisan vendor:publish --provider="Achillesp\CrudForms\CrudFormsServiceProvider" --tag=views

# Tailwind views
php artisan vendor:publish --provider="Achillesp\CrudForms\CrudFormsServiceProvider" --tag=views-tailwind