Git Product home page Git Product logo

laravel-smart's People

Contributors

deiucanta avatar geoffreyvanwyk avatar robsontenorio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-smart's Issues

not install in laravel 9

Hi

i want install this package in laravel 9 but not install and error

Your requirements could not be resolved to an installable set of packages.

Problem 1
- illuminate/support[v5.6.0, ..., 5.8.x-dev] require php ^7.1.3 -> your php version (8.1.13) does not satisfy that requirement.
- deiucanta/smart dev-master requires illuminate/support ^5.6 -> satisfiable by illuminate/support[v5.6.0, ..., 5.8.x-dev].
- Root composer.json requires deiucanta/smart dev-master -> satisfiable by deiucanta/smart[dev-master].

You can also try re-running composer require with an explicit version constraint, e.g. "composer require deiucanta/smart:*" to figure out if any version is installable, or "composer require deiucanta/smart:^2.1" if you know which you need.

Installation failed, reverting ./composer.json to its original content.

[Question] Still active?

I just came across this package and it looks amazing!

Quick question, is there still active development? The current ReadMe states no production use

Error: Class 'Deiucanta\Smart\Rule' not found

public function fields()
    {
        return [
            Field::make('id')->increments(),
            Field::make('code')->unsignedInteger()->unique(),
        ];
    }
 Symfony\Component\Debug\Exception\FatalThrowableError  : Class 'Deiucanta\Smart\Rule' not found

  at /Volumes/BackupHD/dev/laravel-smart/src/FieldRules.php:295
    291|     // url is in FieldTypes
    292|
    293|     protected function makeUniqueRule($model)
    294|     {
  > 295|         $rule = Rule::unique($model->getTable(), $this->name);
    296|
    297|         if ($model->getKey()) {
    298|             $rule->ignore($model->getKey(), $model->getKeyName());
    299|         }

Just missing a import

use Illuminate\Validation\Rule;

Support for User model

The default User model extends Illuminate\Foundation\Auth\User. Since it's not possible to extend two classes, how can we solve this?

Error: change to nullable()

Product.php

<?php

namespace App;

use Deiucanta\Smart\Field;
use Deiucanta\Smart\Model;

class Product extends Model
{
    public function fields()
    {
        return [
            Field::make('id')->increments(),
            Field::make('description')->text(),
        ];
    }
}

Run fine...

php artisan smart:migration
php artisan migrate

So change property from description field to nullable():

    public function fields()
    {
        return [
            Field::make('id')->increments(),
            Field::make('description')->nullable()->text(),
        ];
    }

Then run again ...

php artisan smart:migration
php artisan migrate

Got error...

  RuntimeException  : Changing columns for table "products" requires Doctrine DBAL; install "doctrine/dbal".

  at /var/www/api/vendor/laravel/framework/src/Illuminate/Database/Schema/Grammars/ChangeColumn.php:30
    26|      */
    27|     public static function compile($grammar, Blueprint $blueprint, Fluent $command, Connection $connection)
    28|     {
    29|         if (! $connection->isDoctrineAvailable()) {
  > 30|             throw new RuntimeException(sprintf(
    31|                 'Changing columns for table "%s" requires Doctrine DBAL; install "doctrine/dbal".',
    32|                 $blueprint->getTable()
    33|             ));
    34|         }
```

Converting existing model to Smart model

Let's say you have the user model already. The migration is there and the database is up to date. You want to use Smart model from now on.

Converting the model will generate a new migration as if nothing was in the database. This happens because we didn't track previous states of the user model.

If we add a command that doesn't generate a new migration but updates the smart.json file, I think we should be good on this issue.

Am I missing anything?

Idea: label()

Once this package concerns about validation, I propose implement the method label(). It will properly convert field messages on ValidationException.

Field::make('country_id')->label('Country')->unsignedInteger()->required(),

Will throw Field Country is required instead of Field country id is required.

rule customization

What about a field customization per request? There are cases when you need to validate the fields differently (basic example is admin user). This is done with form requests. So Iโ€™m guessing this package should expose a static method in a model which returns new customized rules (including complete rule removal) which you can use in a form request.

Erro: ID validation

Product.php

<?php

namespace App;

use Deiucanta\Smart\Field;
use Deiucanta\Smart\Model;

class Product extends Model
{
    public function fields()
    {
        return [
            Field::make('id')->increments(),
        ];
    }
}

ProductController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Product;

class SmartController extends Controller
{
    public function index()
    {
        $product = new Product();
        $product->save();
    }
}

Error: "The id must be a number." In this case, ID should be optional once it is incremental.

Idea: lookup models

First, this package gonna rock big time! Hope Taylor addresses it.

Small idea, possibly offscope but anyways: When you register the state of the migrations, could it also register the models itselfs somehow? So we can do something like: app()->models() and get a listing of all the models?

Cheers!

Idea: timestamps()

Like original Laravel migration files. Something like this would be usefull:

<?php

namespace App;

use Deiucanta\Smart\Field;
use Deiucanta\Smart\Model;

class Product extends Model
{
    public function fields()
    {
        return [
            Field::make('id')->increments(),
            Field::make('titulo')->text(),
            Field::timestamps() // or some fancy method name
        ];
    }
}

Idea: foreign() / references()

Just like Laravel migrations it would be useful:

<?php

namespace App;

use Deiucanta\Smart\Field;
use Deiucanta\Smart\Model;

class Product extends Model
{
    public function fields()
    {
        return [
            Field::make('id')->increments(),
            Field::make('user_id')
                  ->unsignedInteger()
                  ->references('id')
                  ->on('users');
        ];
    }
}

Idea: create new fresh smart migration

When developing is common you change database schema often. So, a command like this would delete all previous smart migrations and generate it again. It avoids to have many "smart migration files" while developing in early stages.

php artisan smart:refresh 
// or some fancy name

Plus: any kind of warning on console would be nice (Yes or No, like migrations on production env).

Error: guarded() not working as expected

ProductController.php

class ProductController extends Controller
{
    public function store(Request $request)
    {
        $product = new Product();
        return $product->fill($request->all())->doSomething();
    }
}

Product.php

            Field::make('id')->increments(),
            Field::make('status_id')->unsignedInteger()->guarded(),
            // many others in here ...

I just want guard 'status_id', but i got an error ...

Add [status_id] to fillable property to allow mass assignment on [App\\Product]

But if guarded is declared as default way works fine

protected $guarded = ['status'];

Improvement: Throw an exception when type is not defined

When declaring a field without a type ...

 public function fields()
    {
        return [
            Field::make('code')->unique()->index(),
        ];
    }

It generates a invalid migration with no warnings ...

 Schema::create('products', function (Blueprint $table) {
            $table->("code")->index(true)->unique(true);
        });

Cache `$model->fields()`

  • this would improve performance
  • we can cache it as a collection
  • caching should be inside a static property and based on the class name

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.