pqrs / l5b-crud

CRUD artisan command for rappasoft/laravel-5-boilerplate
21 stars 15 forks source link

Laravel 6 upgrade #15

Open bentran opened 5 years ago

bentran commented 5 years ago

Any plan to upgrade this to support the up coming Laravel 6.0?

pqrs commented 5 years ago

Well, as you have probably imagined, I've been away from Laravel and this project these last months. I didn't have the time to check or fix the reported issues, not to mention have a peek into Laravel 6. Anyway, this project depends on rappasoft's laravel-boilerplate so while it remains based on 5.8 there will be no need to do it.

bentran commented 5 years ago

laravel-boilerplate is now on version 6

pqrs commented 5 years ago

Ops... didn't see that! I checked the github page where it still says it is on 5.8.

Thanks!

bentran commented 5 years ago

I gave the current version a try with 6.x anyway (a fresh Laravel 6.x boiler) Then composer require pqrs/l5b-crud Then php artisan l5b:crud example

Hit an issue with Str functions as that is now moved as per 5.8 to 6.0 upgrade notes. I then ran: composer require laravel/helpers

Ran below again and it now works php artisan l5b:crud example

php artisan migrate

Try to bring up the 'example' route http://lb2.test/admin/examples

Hit below error. Looks like issue is because I have yet to add any examples items. It is hitting the null returned object and then fails over. This is as much I can get up to. Do we need to add a check here to check for null??

App\Repositories\Backend\ExampleRepository::getActivePaginated :34
...\www\lb2\app\Repositories\Backend\ExampleRepository.php

Line #34 is: ->orderBy($orderBy, $sort)

public function getActivePaginated($paged = 25, $orderBy = 'created_at', $sort = 'desc') : LengthAwarePaginator

    {

        return $this->model

            ->orderBy($orderBy, $sort)

            ->paginate($paged);

    }
Sgtpsyco23 commented 4 years ago

I have the same problem. I have added a dummy record to the database and it still throws the same error? I can see the record with tinker? Any idea how to solve this as i would really like to use this crud creator.

Sgtpsyco23 commented 4 years ago

Okay seems we have have to add a construct method public function construct(Example $model) { $this->model = $model; } Cheers John

bentran commented 4 years ago

Thanks @Sgtpsyco23 that works!

Just to be clear. The construct method needs to be added to the app\Repositories\Backend\ExampleRepository.php file

bentran commented 4 years ago

Taking the fix one step further:

modify the file below file

vendor\pqrs\l5b-crud\src\Console\Commands\Stubs\make-repository.stub

and add the construct method to it so it now looks like:

class DummyRepository extends BaseRepository
{

    public function __construct(DummyModel $model)
    {
        $this->model = $model;
    }

    /**
     * @return string
     */
    public function model()
    {
        return DummyModel::class;
    }

I will do further testing. Hopefully that is all that is needed!

bentran commented 4 years ago

Can someone explain why previously loading the model in construct was not needed?

bentran commented 4 years ago

Something else to consider is to rename / refactor this to l6crud to reflect the changes or something more generic?

bentran commented 4 years ago

Here goes the next hurdle!

When you try to create a new entry it comes up with below error as the create method does not exist in the base BaseRepository

Symfony\Component\Debug\Exception\FatalThrowableError Call to undefined method App\Repositories\BaseRepository::create()

public function create(array $data) : Example
    {
        return DB::transaction(function () use ($data) {

===>            $example = parent::create([

                'title' => $data['title'],

            ]);

            if ($example) {

                return $example;

            }

            throw new GeneralException(__('backend_examples.exceptions.create_error'));

        });
    }
dividemysky commented 4 years ago

I've created a pull request that should enable support for the Laravel 6 version of Boilerplate:

16

bentran commented 4 years ago

I've created a pull request that should enable support for the Laravel 6 version of Boilerplate:

16

So far looking good. Thanks!

neppoz commented 4 years ago

Hello all,

i have a question, since i did't do that so far. How is it possible to test the pull request prior to the merge? How to do that with composer? Should i add the commit reference?

"require": { "vendor/package": "dev-master#?????" }

Maybe someone can give me an advice.

dividemysky commented 4 years ago

@neppoz if you're looking to override a composer repo with a different branch you can add something like this to your composer.json file:

"repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/dividemysky/l5b-crud/"
        }
    ],
    "require": {
        .....
        "pqrs/l5b-crud": "dev-dev-l5bcrud",
          ....
    },

This would use my fork of this project.

neppoz commented 4 years ago

Hi,

i used the fork on your project. But i think the error is not only related on your fork. When i create a new CRUD i got this error:

php artisan l5b:crud mynewtable

Symfony\Component\Debug\Exception\FatalThrowableError : Call to undefined function pqrs\L5BCrud\Console\Commands\snake_case()

So i gave it a quick try and included the Helper in L5BCrud.php. use Illuminate\Support\Str;

Then i replaced the strings with Str::

Afterwords it worked. Any ideas ?

bentran commented 4 years ago

Afterwords it worked. Any ideas ?

Refer to my post above. In short you need laravel/helpers due to changes in Laravel 6

composer require laravel/helpers

neppoz commented 4 years ago

Ok, missed that info. Thank you

bentran commented 4 years ago

Here goes the next hurdle! When you try to create a new entry it comes up with below error as the create method does not exist in the base BaseRepository

Symfony\Component\Debug\Exception\FatalThrowableError Call to undefined method App\Repositories\BaseRepository::create()

public function create(array $data) : Example
    {
        return DB::transaction(function () use ($data) {

===>            $example = parent::create([

                'title' => $data['title'],

            ]);

            if ($example) {

                return $example;

            }

            throw new GeneralException(__('backend_examples.exceptions.create_error'));

        });
    }

Check this link: rappasoft/laravel-boilerplate#1284 (comment)

Refer to above. This has been solved!