Giter Club home page Giter Club logo

laravel-cms-models's Introduction

Latest Version on Packagist Software License Build Status Coverage Status

CMS for Laravel - Main Models Module

This module offers the means to edit Eloquent models through the Laravel CMS.

Features:

  • Model listings
  • Edit forms for creating and updating model records
  • Elaborate (optional) module configuration and customization.
    • Customizable listing columns, scopes, filters, sorting, etc.
    • Customizable edit form html, fields, validation rules, create vs. edit forms, etc.
    • Customizable model references, display labels, etc.
  • Support for Translatable models
  • Support for Listify'd models, with drag/drop reordering
  • Support for nested child-parent listings and breadcrumb trails

To be used to with the Laravel CMS Core.

For a better end-user experience when using file uploads, installing the Laravel CMS Upload Module is recommended.

Version Compatibility

Laravel Package
5.3 1.3
5.4 1.4
5.5 1.5
5.6 1.6
5.7 1.7

Changelog

View the changelog.

Installation

Add the module class to your cms-modules.php configuration file:

    'modules' => [
        // ...
        Czim\CmsModels\Modules\ModelModuleGenerator::class,
    ],

Add the service provider to your cms-modules.php configuration file:

    'providers' => [
        // ...
        Czim\CmsModels\Providers\CmsModelsServiceProvider::class,
        // ...
    ],

To publish the config:

php artisan vendor:publish

Configuration

Models may be added with basic functionality by simply registering them in the cms-models config, or special CMS model configuration files may be created for them to customize them as needed.

Adding and Configuring Models

To register models with the CMS module, you can either:

  • Add their full class name to the cms-models.models config array:

    <?php
          'models' => [
              App\Models\YourModel::class,
          ],
  • Create a model configuration file for them in the configured directory.
    By default, this is in the app/Cms/Models/ directory; this is defined under the cms-models.collector.source.dir key.

For more details about customizing how models are configured, see the documentation on Model Configuration.

Troubleshooting

If you run into problems, please consult the CMS core troubleshooting section.

Further information

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

laravel-cms-models's People

Contributors

czim avatar daniel-de-wit avatar jjwesterkamp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

laravel-cms-models's Issues

Allow setting a default value for a form field (store) strategy

This should (at least) be possible in the context of creating a new record.

Should probably support:

  • default key
  • that may optionally be a callable or even a class alias (that should implement an interface)
  • otherwise, if scalar/literal, should be taken literally if the value is empty when creating a model

PHP 7.2 support

PHP 7.2 changed count() to throw an E_WARNING when attempting to count non-countable types (this includes the sizeof() alias function).

PHP RFC: Counting of non-countable objects

Migrating from PHP 7.1.x to PHP 7.2.x

I suggest adding some sort of helper function to check if a variable contains a countable object before
counting it, something like this:

function is_countable ($value) {
    return is_array($value) || $value instanceof Countable;
}

Where should this function be placed?

Feature: add list column strategy for toggling boolean fields

It should be easy to add a simple boolean toggle to a model listing.

  • The DefaultModelController should support this (with all the usual security checks).
  • A ListColumn display strategy should be included for this.

This should function similarly to the column activate toggle.

Resolve foreign-key columns the laravel-5.4-way for model relations

Starting with Laravel 5.4, foreign key fields for Eloquent relations are resolved by the related model's primary key name and table name. According to the Laravel upgrade guide:

If the foreign key is not explicitly specified when defining a relationship, Eloquent will now use the table name and primary key name for the related model to build the foreign key. For the vast majority of applications, this is not a change of behavior.

For example:

/**
 * @property int $id - The primary key of Project
 */
class Project extends Model
{
    // this model's table name would be 'projects', so any foreign key would be
    //  built as 'project_id' by default, starting from Laravel 5.4
}

This means that I should be able to name my relation methods anything I see fit to provide some semantics, such as in the example below, where the relation method points to a certain Employee's favorite Project:

// Some other model that 'belongsTo' project...

class Employee extends Model
{
    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function favoriteProject()
    {
        return $this->belongsTo(Project::class);
    }
}

Within Laravel itself everything works as expected, but when I try to load the above model in the CMS, I get the following error:

Issue analysing model App\Models\Employee:

Foreign key ‘favorite_project_id’ defined for relation does not exist on model App\Models\Employee

Am I missing some configuration step? The workaround I have for now is just explicitly specifying the foreign key name in the belongsTo call, but I'd prefer to be able to omit that second argument:

return $this->belongsTo(Project::class, 'project_id');

Relevant info from my composer.json file:

{
    "require": {
        "czim/laravel-cms-acl-module": "0.9.3",
        "czim/laravel-cms-auth": "1.4.2",
        "czim/laravel-cms-core": "1.4.6",
        "czim/laravel-cms-models": "1.4.4",
        "czim/laravel-cms-theme": "0.9.8",
        "czim/laravel-cms-upload-module": "1.0.2",
    }
}

Add option for default model list scope

For example, i've added a 'active' scope which filters the records bases on an active column boolean.

This gives me 2 tabs above the model list view, "All" and "Active". Now I wish to have "Active" selected as the default scope for my model.

List Parent setup and Default top relation documentation incomplete

It's still pretty unclear from the documentation how List Parent setups can be made.

The default_top_relation comment is incomplete (dangling comma).

It would also help to add an example where the relation is between two separate models (f.i. a HasMany between a product and its variants).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.