PHPackages                             bakle/crud-core - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. bakle/crud-core

ActiveLibrary[Framework](/categories/framework)

bakle/crud-core
===============

Laravel Crud core files

1.2.0(2y ago)134MITPHPPHP ^8.2

Since Sep 20Pushed 2y ago1 watchersCompare

[ Source](https://github.com/bakle/crud-core)[ Packagist](https://packagist.org/packages/bakle/crud-core)[ RSS](/packages/bakle-crud-core/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (3)Versions (13)Used By (0)

Laravel CRUD Core
=================

[](#laravel-crud-core)

This package contains base files that contains all boilerplate logic for creating a crud.

Installation
------------

[](#installation)

```
composer require bakle/crud-core
```

What's inside this package?
---------------------------

[](#whats-inside-this-package)

UrlPresenter
------------

[](#urlpresenter)

The url presenter encapsulate the routes that are generated in `Route::resource('users, UserController::class)`

### For one model

[](#for-one-model)

```
class UserUrlPresenter extends BaseUrlPresenter
{

    function getRouteName(): string
    {
        return 'users';
    }
}

// --- Examples ---

// Url presenter for routes that doesn't depend on a specific model (index, create)
$userUrlPresenter = new UserUrlPresenter();
$userUrlPresenter->index(); // --> /users
$userUrlPresenter->create(); // --> /users/create
$userUrlPresenter->store(); // --> /users (for post method)

// Url presenter for routes that depend on a specific model (show, edit, update, delete )
$user = User::first();
$userUrlPresenter = new UserUrlPresenter($user);
$userUrlPresenter->index(); // --> /users
$userUrlPresenter->show(); // --> /users/1
$userUrlPresenter->create(); // --> /users/create
$userUrlPresenter->store(); // --> /users (for post method)
$userUrlPresenter->edit(); // --> /users/1/edit
$userUrlPresenter->update(); // --> /users/1
$userUrlPresenter->destroy(); // --> /users/1

```

### For related models

[](#for-related-models)

```
class UserPostCommentUrlPresenter extends BaseUrlPresenter
{

    function getRouteName(): string
    {
        return 'users.posts.comments';
    }
}

class Post extends \Illuminate\Database\Eloquent\Model
{

    public function getRouteKeyName(): string
    {
        return 'slug';
    }
}

// Example

$user = User::first();
$post = Post::first();
$comment = Comment::first();

$urlPresenter = new UserPostCommentUrlPresenter($user, $post, $comment);
$userUrlPresenter->index(); // --> /users/1/posts/the-post-slug/comments
$userUrlPresenter->show(); // --> /users/1/posts/the-post-slug/comments/1
$userUrlPresenter->create(); // --> /users/1/posts/the-post-slug/comments/create
$userUrlPresenter->store(); // --> /users/1/posts/the-post-slug/comments (for post method)
$userUrlPresenter->edit(); // --> /users/1/posts/the-post-slug/comments/1/edit
$userUrlPresenter->update(); // --> /users/1/posts/the-post-slug/comments/1
$userUrlPresenter->destroy(); // --> /users/1/posts/the-post-slug/comments/1
```

Entities
--------

[](#entities)

An entity is an extra layer that wraps your model to add extra logic. The `BaseEntity` only require a `url()` method to be implemented

```
class UserEntity extends BaseEntity
{

    public function url(): ?BaseUrlPresenter
    {
        return new UserUrlPresenter($this->model);
    }
    ... // more methods
}

// Example single model
$user = User::first();
$userEntity = new UserEntity($user);

$user->entity->getCreatedAtDayDateFormat(); // Sat, Oct 7, 2023

// Example multiple model
$users = User::all();
$userEntities = UserEntity::collection($users);

$userEntities->first()->url()->show() // /users/1
```

View Models
-----------

[](#view-models)

View models encapsulates all the logic and data that you need to send to your views.

### IndexViewModel

[](#indexviewmodel)

This view model send to the view the following data:

- **entities:** A collection of the entities of the model defined in the `IndexViewModel` (i.e: UserEntity)
- **pagination:** Because now you receive a collection of entities and not models, this is the same as doing `$users->links`. now you can do: ```

      {!! $pagination !!}

    ```
- **title:**: This is just the string you return in the `getTitle()` method. It's useful in your index to add it in your blade like this:

```
    {{ $title }}

```

#### Example

[](#example)

```
class UserIndexViewModel extends BaseIndexViewModel
{
    public function getTitle(): string
    {
        return trans('Users');
    }

    public function getEntityClass(): string
    {
        return UserEntity::class;
    }
}

// In the UserController
class UserController extends Controller
{
    public function index(Request $request): View
    {
        $users = User::query()->with('roles');

        return view('users.index',
            (new UserIndexViewModel($users, $request))->build()
        );
    }
}
```

### ShowViewModel

[](#showviewmodel)

This view model send to the view the following data:

- **entity:** A single entity of the model defined in the `ShowViewModel` (i.e: UserEntity)

#### Example

[](#example-1)

```
class UserShowViewModel extends BaseShowViewModel
{
    public function getTitle(): string
    {
        return trans('User');
    }

    public function getEntityClass(): string
    {
        return UserEntity::class;
    }

    protected function getExtraData(): array
    {
        return [
            'title' => $this->getTitle()
        ];
    }
}

// In your UserController
class UserController extends Controller
{
    public function show(User $user)
    {
        $user->load('roles');

        return view('users.show', (new UserShowViewModel($user))->build());
    }
}
```

### FormViewModel

[](#formviewmodel)

This view model send to the view the following data:

- **entity:** A single entity of the model defined in the `ShowViewModel` (i.e: UserEntity)
- **form:** This contains the url for submitting the form, the method type (POST or PUT) and some other helper methods. It's useful to use it in your forms like this:

```

        @csrf
        @method($form->getMethod())

    //...your fields

        @if($form->isEditType())
            {{ trans('Update') }}
        @else
            {{ trans('Create') }}
        @endif

```

- **title:**: This will resolve automatically the title based on the method type. For example if you use `->setFormType(FormTypes::CREATE)`, the title will be ***Create user***, if it's `->setFormType(FormTypes::EDIT)`, the title will be ***Edit User***. You can use it like this:

```
    {{ $title }}

```

#### Example

[](#example-2)

```
class UserFormViewModel extends BaseFormViewModel
{

    protected function getEntityClass(): string
    {
        return UserEntity::class;
    }

    protected function getExtraData(): array
    {
        return [
            'roles' => Role::query()->get();
        ];
    }
}

// In your UserController

class UserController extends Controller
{

    public function create(): View
    {
        return view('users.form',
            (new UserFormViewModel(new User()))->setFormType(FormTypes::CREATE)->build()
        );
    }

    public function edit(User $user): View
    {
        return view('users.form',
            (new UserFormViewModel($user))->setFormType(FormTypes::EDIT)->build()
        );
    }
}
```

All `ViewModel` includes a method `getExtraData()` where you can return an array of extra data you need to send to the view.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~19 days

Total

6

Last Release

853d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9258309c05b4bb41cd7cafd23d54d4303da8f1e913e77bda6268b161a8bd89e4?d=identicon)[bakle](/maintainers/bakle)

---

Top Contributors

[![bakle](https://avatars.githubusercontent.com/u/10352801?v=4)](https://github.com/bakle "bakle (33 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bakle-crud-core/health.svg)

```
[![Health](https://phpackages.com/badges/bakle-crud-core/health.svg)](https://phpackages.com/packages/bakle-crud-core)
```

###  Alternatives

[codewithdennis/larament

Larament is a time-saving starter kit to quickly launch Laravel 13.x projects. It includes FilamentPHP 5.x pre-installed and configured, along with additional tools and features to streamline your development workflow.

3691.5k](/packages/codewithdennis-larament)[ecotone/laravel

Laravel integration for Ecotone

21307.6k3](/packages/ecotone-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
