deiucanta / laravel-smart Goto Github PK
View Code? Open in Web Editor NEWAutomatic Migrations, Validation and More
Automatic Migrations, Validation and More
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.
I just came across this package and it looks amazing!
Quick question, is there still active development? The current ReadMe states no production use
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;
The default User
model extends Illuminate\Foundation\Auth\User
. Since it's not possible to extend two classes, how can we solve this?
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| }
```
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?
Field::make('comments')->hasMany(Comment::class);
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
.
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.
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.
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!
Those are available since MySQL 5.7.
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
];
}
}
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');
];
}
}
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).
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'];
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);
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.