Laravel-Backpack / Generators

Generate files for Backpack projects
http://backpackforlaravel.com
MIT License
314 stars 64 forks source link

BadMethodCallException : Method Illuminate\Support\Str::of does not exist. while running php artisan backpack::crud #115

Closed salmanaligeek closed 3 years ago

salmanaligeek commented 3 years ago

Bug report

What I did:

php artisan backpack::crud Test or php artisan backpack:crud-controller Test

What I expected to happen:

New backpack CRUD controller

What happened:

    BadMethodCallException  : Method Illuminate\Support\Str::of does not exist.

  at /home/salman/Work/FixingBug/vendor/laravel/framework/src/Illuminate/Support/Traits/Macroable.php:77
    73|      */
    74|     public static function __callStatic($method, $parameters)
    75|     {
    76|         if (! static::hasMacro($method)) {
  > 77|             throw new BadMethodCallException(sprintf(
    78|                 'Method %s::%s does not exist.', static::class, $method
    79|             ));
    80|         }
    81| 

  Exception trace:

  1   Illuminate\Support\Str::__callStatic("of")
      /home/salman/Work/FixingBug/vendor/backpack/generators/src/Console/Commands/CrudBackpackCommand.php:31

  2   Backpack\Generators\Console\Commands\CrudBackpackCommand::handle()
      /home/salman/Work/FixingBug/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36

Backpack, Laravel, PHP, DB version:

Laravel 6.20.30, PHP 7.3, MariaDB 10.3.29

welcome[bot] commented 3 years ago

Hello there! Thanks for opening your first issue on this repo!

Just a heads-up: Here at Backpack we use Github Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.

Backpack communication mediums:

Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.

Thank you!

-- Justin Case The Backpack Robot

pxpm commented 3 years ago

Hello @salmanaligeek thanks for the report.

Indeed I can confirm that we added a function that is not supported in all Laravel versions that we support in CRUD. I see you are using Laravel 6. Sorry for the trouble, we will try to come up with a solution as soon as possible.

I think we can port that function back to L6 by using macros.

ping @tabacitu

Str::of does not exist in Laravel 6.

I think an easy fix is to add a macro in case it doesn't exist:

//GeneratorsServiceProvider.php

//check if method `of` exists in Str class, if not register it

Str::macro('of', function (..) {
// replicate laravel code for `of` function
})

What do you think ?

Best, Pedro

tabacitu commented 3 years ago

Ouch! Yeah we probably forgot we support L6 too... sorry @salmanaligeek !

Seems like this has happened in this commit https://github.com/Laravel-Backpack/Generators/commit/8597e4eed25d7b8d5fd8c07ef0cb9ed3ac37eb44 - when @promatik fixed stuff, he also started using the Fluent Helpers. I didn't notice it in my review, sorry. It would have been fine if we dropped support for L6 right then and there, but now that we have tagged versions with L6 support and Str::of()... we're forced to fix it and keep L6 support.

I don't think adding a Macro would be an easy way out... I expect it's not as easy as that to add Fluent Strings to L6.

I think our best bet is to rewrite those bits to no longer use the Fluent String Helpers, but normal String Helpers. Even though the code would be uglier, it'll support L6-L8 and fix the problem.

pxpm commented 3 years ago

@tabacitu

I've just had a grip on this, and the macro part is just that easy:

// notice `off` because I am in a version where `of` is available
if(class_exists('\Illuminate\Support\Str') && !method_exists('\Illuminate\Support\Str', 'off')) {  
            \Illuminate\Support\Str::macro('off', function($string) {
                return new \Illuminate\Support\Stringable($string);
            });
        }

Problem is that in L6 there is no \Illuminate\Support\Stringable class. So yeah, in this specific scenario is better to just write with other Str functions, otherwise the macro would be just fine! :)

I will assign myself to this and fix it.

Thanks, Pedro

promatik commented 3 years ago

My bad, sorry πŸ™ƒ

@pxpm I did the mess, I fix it πŸ˜… the PR is here; https://github.com/Laravel-Backpack/Generators/pull/116

$nameTitle = Str::of($name)->afterLast('\\');
$nameKebab = $nameTitle->kebab();
$nameSingular = $nameKebab->replace('-', ' ');
$namePlural = $nameSingular->plural();

This was so beautiful πŸ€·β€β™‚οΈ

Keanhor2 commented 1 year ago

Hello brother this is my error at below when I try to migrate database Do you have any solutions? thanks in advance

Migrating: 2014_10_12_000000_create_users_table

BadMethodCallException

Method Illuminate\Database\Schema\Blueprint::strong does not exist.

at vendor/laravel/framework/src/Illuminate/Macroable/Traits/Macroable.php:113 109β–• */ 110β–• public function __call($method, $parameters) 111β–• { 112β–• if (! static::hasMacro($method)) { ➜ 113β–• throw new BadMethodCallException(sprintf( 114β–• 'Method %s::%s does not exist.', static::class, $method 115β–• )); 116β–• } 117β–•

β€’ Bad Method Call: Did you mean Illuminate\Database\Schema\Blueprint::string() ?

1 database/migrations/2014_10_12_000000_create_users_table.php:35 Illuminate\Database\Schema\Blueprint::__call()

+4 vendor frames 6 database/migrations/2014_10_12_000000_create_users_table.php:44 Illuminate\Support\Facades\Facade::__callStatic()

pxpm commented 1 year ago

@Keanhor2 I think in that migration you have a typo, and instead of $table->string() you have written $table->strong().

tabacitu commented 1 year ago

Strong columns are the best!

angry-power-gif-by-spongebob-squarepants

Keanhor2 commented 1 year ago

Hello brother ! again I have a problem when I try to compile vue js in laravel :

webpack compiled successfully Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/cguser/Personal project/khmer_food/resources/sass' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/cguser/Personal project/khmer_food' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/cguser/Personal project' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/cguser' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/cguser/Personal project/khmer_food/resources' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/cguser/Personal project/khmer_food/resources/js/components' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/cguser/Personal project/khmer_food/public' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/cguser/Personal project/khmer_food/resources/js/components' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/cguser/Personal project/khmer_food/public' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/cguser/Personal project/khmer_food/resources' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/cguser/Personal project/khmer_food' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/cguser/Personal project' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/cguser' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/cguser/Personal project/khmer_food/resources/sass' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/cguser/Personal project/khmer_food/public' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/cguser/Personal project/khmer_food/resources' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/cguser/Personal project/khmer_food' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/cguser/Personal project' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/cguser/Personal project/khmer_food/public' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/cguser/Personal project/khmer_food/resources' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/cguser/Personal project/khmer_food' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/cguser/Personal project/khmer_food/public' Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/cguser/Personal project/khmer_food/resources'

tabacitu commented 1 year ago

Sorry @Keanhor2 that has nothing to do with this thread. If you think it's Backpack-related, open a different issue. But it looks to me like it's got nothing to do with Backpack, but VueJS/Laravel. Cheers!

Keanhor2 commented 1 year ago

Hello all be loved brother ! Can you help to solve this problem :

  1. here is my script : For this I uesd laravel and vue js.

//=========================problem ============================= 1, image

2, image

tabacitu commented 1 year ago

@Keanhor2 no. Please stop posting non-Backpack issues here - this is spam. This is your second warning - third time you'll get banned.