Method Illuminate\Support\Str::replace does not exist - laravel

I am using:
Laravel Version: 8.35.1
PHP Version: 7.4.9
On Tinker and Routing I use Str::replace() method as in the docs but get error:
BadMethodCallException with message Method Illuminate\Support\Str::replace does not exist.
Example 1:
root#c6dd4af63e3c:/var/www/html# php artisan tinker
Psy Shell v0.10.7 (PHP 7.4.9 — cli) by Justin Hileman
>>> Illuminate\Support\Str::replace('8.x', '9.x', 'Laravel 8.x');
BadMethodCallException with message 'Method Illuminate\Support\Str::replace does not exist.'
>>>
Example2:
Route::get('/test', function () {
return Illuminate\Support\Str::replace('8.x', '9.x', 'Laravel 8.x');
});
Why do I have this error and how to fix it?

String Replace method Illuminate\Support\Str::replace introduced in Laravel version v8.41.0
Ref:https://github.com/laravel/framework/releases/tag/v8.41.0

Related

artisan backpack:build fails with BadMethodCallException

In a fresh Backpack installation, when I run php artisan backpack:build it fails as follows:
BadMethodCallException
Method Illuminate\Support\Stringable::value 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\Support\Stringable::headline() ?
+16 vendor frames
17 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
I'm running php 7.3.33 and laravel 8.83.27 and backpack/crud: 5.4.16 and backpack/generators: v3.3.13
UPDATE 2/15/23: I've updated the server to php 7.4.33, but the problem is unchanged.
Is this a bug, or have I done something wrong?

Using the tinker function in laravel

Im using the tinker function in laravel but when i type the following in:
>>>user App\PostController;
>>>PostController::get();
I get the following error:
PHP Fatal error: Class 'App/PostController' not found in Psy Shell code on line 1
How do i fix this?
You can use the following:
$controller = app()->make(App\Http\Controllers\PostController::class);
app()->call([$controller, 'get']);
If you want to pass arguments to the method:
$controller = app()->make(App\Http\Controllers\PostController::class);
app()->call([$controller, 'get'], ['test' => 123]);
Controllers are under App\Http\Controllers namespace
try use App\Http\Controllers\PostController

How to Install Swagger-UI to Laravel 6 API for doumentation?

Installing Swagger for the First Time in laravel 6. https://github.com/DarkaOnLine/L5-Swagger.
composer require "darkaonline/l5-swagger"
php artisan vendor:publish --provider "L5Swagger\L5SwaggerServiceProvider"
On generating command
php artisan l5-swagger:generate
Getting Error like:
php artisan l5-swagger:generate
Regenerating docs
ErrorException : Required #OA\Info() not found
at D:\XMAPP\htdocs\minidmsapi\vendor\zircote\swagger-php\src\Logger.php:39
35| $this->log = function ($entry, $type) {
36| if ($entry instanceof Exception) {
37| $entry = $entry->getMessage();
38| }
> 39| trigger_error($entry, $type);
40| };
41| }
42|
43| /**
Exception trace:
1 trigger_error("Required #OA\Info() not found")
D:\XMAPP\htdocs\minidmsapi\vendor\zircote\swagger-php\src\Logger.php:39
2 OpenApi\Logger::OpenApi\{closure}("Required #OA\Info() not found")
D:\XMAPP\htdocs\minidmsapi\vendor\zircote\swagger-php\src\Logger.php:71
Please use the argument -v to see more details.
please Help me for generating swagger documentation
Required #OA\Info() is required to initialize your swagger documentation and then use proper annotation to parse. Annotations are only parsed inside /** DocBlocks. Here you go for initial annotations swagger-php#usage

Generating models from existing database at once

I'm trying to generate models from an existing database at once without having to do it separately for all tables. I have tried to do this with reliese/laravel. I have executed:
php artisan -v code:models
However, I'm getting the following error.
ErrorException : mkdir(): Invalid path
at C:\xampp\htdocs\schaden\vendor\laravel\framework\src\Illuminate\Filesystem\Filesystem.php:466
462| if ($force) {
463| return #mkdir($path, $mode, $recursive);
464| }
465|
466| return mkdir($path, $mode, $recursive);
467| }
468|
469| /**
470| * Move a directory.
Exception trace:
1 mkdir("")
C:\xampp\htdocs\schaden\vendor\laravel\framework\src\Illuminate\Filesystem\Filesystem.php:466
I'm not posting the full error stack here. Can anyone help?
Probably the best solution is using the package Eloquent Model Generator that you can find on github at https://github.com/krlove/eloquent-model-generator.
Then you can easily use, for example, php artisan krlove:generate:model User --table-name=users or php artisan krlove:generate:model MyModel --table-name=my_models and use some of the package options.

Laravel 5.4 route name not working

In my routes on web.php I have the following line
Route::get('/', 'DashboardController#create')->name('dashboard');
In my DashboardController.php I have a create function with the following line like I saw on a Laracast tutorial but it's not working.
return redirect()->dashboard();
I get the following error
(1/1) FatalThrowableError
Call to undefined method Illuminate\Routing\Redirector::dashboard()
What could I be doing wrong?
You should use
return redirect()->route('dashboard');
this is the way to do it.
visit Named Routes for more info
return redirect()->dashboard(); calls a method named as dashboard inside your controller and that's what error is saying
(1/1) FatalThrowableError
Call to undefined method
Illuminate\Routing\Redirector::dashboard()
You need to call named routes like this
return redirect()->route('dashboard');
For deep insight always trust laravel docs
Instead of:
return redirect()->dashboard();
Try:
return redirect()->route('your-route-name');

Resources