laravel / ideas

Issues board used for Laravel internals discussions.
939 stars 28 forks source link

[Proposal][5.4] A real backend / CRUD scaffolding for models #274

Closed MarceauKa closed 6 years ago

MarceauKa commented 8 years ago

Hi!

With Laravel I really love all goodies like Echo, Socialite, Cashier, Notifications, etc, to fastly build a modern app I think a CRUD builder can be a good idea.

Something like that would be a great idea:


class Post extends Model
{
    use Crudable;

    public function crudFields()
    {
        return [
            'title' => (new TextInput())->rules('required|max:100'),
            // Use a custom ID for this field
            'introduction' => (new TextareaInput())->rules('required|max:100')->withId('myCustomId'),
            // Load a custom blade view to inject by textarea template
            'content' => (new TextareaInput())->rules('required')->useView('partials.fields.my-custom-text-area-template');
        ];
    }
}

In a controller for listing entries:

    public function all()
    {
        $posts = Post::all();

        return view('back.posts.all')->with(['posts' => $posts]);
    }

    public function update($id)
    {
        $post = Post::findOrFail($id);

        return view('backend.posts.update')->with(['post' => $post]);
    }

backend/posts/all.blade.php:

{!! $posts->crud()->all(25) !!}

backend/posts/update.blade.php:

{!! $post->crud()->form() !!}

It's just an example. But I think it can be a very good start to scafffold a simple admin. Of course all views for fields an tables would be customizable like pagination views are in 5.3.

What do you think?

fulopattila122 commented 8 years ago

It already exists: https://github.com/appzcoder/crud-generator/

This is not the only one, but I've used it and it does the initial scaffolding pretty well. Then you can alter generated files as per your needs.

MarceauKa commented 8 years ago

I knew (but I never used this one). But this is exactly why I made this proposal, there's a ton of CRUD implementation (I mainly use Streams Platfom). I like the Taylor's coding style, and I think an official package integrated by default could help newcomers to build something really cool around this (potential) new feature. I know that's can't be a big priority and all of this is just a point of view but I just like the idea :)

Edit: The package you linked is just a scaffolding via Artisan commands, not really a real CRUD. For Laravel 5.4 I image a real CRUD builder giving us Events, real API (for fields, for migrations, etc), not just a scaffolding via stubs.

mclxly commented 8 years ago

+1, a CRUD generator like RoR will be cool

DesmondPang commented 8 years ago

+1 Making a optional package is good just like Socialite. The only thing I don't feel good with Laravel is no official CRUD generator. Compare to the most popular web framework in Python, Django, It has a simple CRUD generator. You can easily create an admin panel to manage all models and their relationships. RoR also has CRUD generator.

I know there are some existing CRUD packages. I have tried many packages but I personally think that they are not reliable.

mohammed-alsiddeeq commented 8 years ago

There is also a library called backpack give it a try

jacurtis commented 8 years ago

I agree it would be cool. I think he is referring to something similar to Ruby on Rails which has basic crud scaffolding in its console commands (equivalent to php artisan).

For me, instead of baking this directly into Laravel, I would love to see it in the form of a first-party package (like cashier/scout). This is a popular feature people would use often but having a first party package would guarantee that it would be kept compatible and up to date with future versions of Laravel and maintained as part of the community.

An example that comes to mind is the entrust package which has been largely abandoned even though it is massively popular. Hundreds of issues sit on github waiting to be resolved and no activity for many months. This sucks when a developer relies on a package that is so critical to their application and they can't know for certain that it's going to be maintained.

Taylor could even reach out to one of these packages that already exist and "promote" them to first party package and bring it under the Laravel organization here on Github. This might save a lot of time re-writing existing code for this. But we could just make that one package amazing instead.

seanmangar commented 8 years ago

+1 I think it would be cool to have a first party Laravel 5 Generators package that provides a bunch of power tools for developers who need to get repetitive tasks done, like crud scaffolding, generating pivot tables, models, etc.

I agree with you jacurtis. A first party package would bring a lot of advantages like you mentioned. Those guarantees are very important when you are building applications that will evolve over several years. It's quite negative to the developer experience to have poor quality packages lying around that are not well maintained.

mohammed-alsiddeeq commented 8 years ago

Another package Here

Truemedia commented 8 years ago

Iv'e been working on something like this for generating any laravel file you can think of.

https://github.com/Truemedia/slush-regenerator

The only thing at the minute is I'm doing some major refactoring to split tasks and allow parameters, aswell as making the most of the nodejs ecosytem to build the files.

MarceauKa commented 8 years ago

I'm working on a CRUD package (still proof of concept, not fully working): https://github.com/AkibaTech/laravel-crudable

sohelamin commented 8 years ago

In the beginning I was missing a complete CRUD generator in laravel. There was only one generator exists (Jeffry's one though not the CRUD generator) Then I've made simpler one https://github.com/appzcoder/crud-generator (which is inspired by Yii's Gii Tool)

Now I've another more convenience admin tool https://github.com/appzcoder/laravel-admin

MarceauKa commented 8 years ago

@sohelamin Your package is good! But it's more like commands that generate code than a real API.

0config commented 7 years ago

Hi Everyone,

Indeed, i missed the same, once i started playing around with Python Django. I create one for my self. Later shared with my friends, people started liking it and I published online to public here. It doesn't do much, but will save a lot of your time..

Try it out: http://dry-project.lateraljs.org/laravel_gen/

If you have any question or issue, please drop it here. https://github.com/0config/laravel-ps-ex/issues

Minimim config download is in github: https://github.com/0config/laravel-ps-ex/blob/master/readme.md

judgej commented 7 years ago

Ah, everyone is looking for a CRUD generator, so everyone starts their own. Now we have ten half-complete CRUD generators that nobody has time to maintain by themselves :-( It frustrates me when I think about what we could have if one approach was lead from the top.

cjke commented 6 years ago

You could also contribute to the one that is closest to your requirements.

I get that people want it as part of core or "from the top" but it's OSS - there should be no top.