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
Related
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
I added "beyondcode/laravel-dump-server": "^1.2"
to my Laravel 5.7 application and sometimes I got error
[2018-10-18 03:44:02] local.ERROR: Argument 1 passed to Symfony\Component\VarDumper\Dumper\HtmlDumper::dump() must be an instance of Symfony\Component\VarDumper\Cloner\Data, null given, called in /mnt/_work_sdb8/wwwroot/lar/Votes/vendor/symfony/var-dumper/Command/Descriptor/HtmlDescriptor.php on line 47 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Argument 1 passed to Symfony\\Component\\VarDumper\\Dumper\\HtmlDumper::dump() must be an instance of Symfony\\Component\\VarDumper\\Cloner\\Data, null given, called in /mnt/_work_sdb8/wwwroot/lar/Votes/vendor/symfony/var-dumper/Command/Descriptor/HtmlDescriptor.php on line 47 at /mnt/_work_sdb8/wwwroot/lar/Votes/vendor/symfony/var-dumper/Dumper/HtmlDumper.php:111)
[stacktrace]
I run server in my console as :
php artisan dump-server --format=html > public/dump.html
I added wrapper method to commom trait of my app:
<?php
namespace App\Http\Traits;
use File;
use Barryvdh\Debugbar\Facade as Debugbar;
use Carbon\Carbon;
use Config;
use Intervention\Image\Facades\Image as Image;
trait funcsTrait
{
public function d($data)
{
if (empty($data)) {
return;
}
dump($data);
}
and calling this method in my control :
$this->d('ProfilePageTest Test51:: $newUserSessionData::' . print_r($newUserSessionData, true));
And sometimes I got error described above.
In my wrapper I tried to exclude calling of dump with empty value, supposing that empty value could be reason of this error ?
But looks like the reason was different. If there is a way make work it properly?
Thanks!
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');
I have an issue with my Laravel installation and the use of Adldap...
The error message I receive :
FatalThrowableError in UserCreationController.php line 100:
Class 'App\Http\Controllers\Adldap' not found
I have installed/deployed Adldap according to the documentation and it is working when I call it from some other location.
Working stuff :
Route::get('ldap', function() {
$results = Adldap::search()->where('ou', 'ends_with', ' Users')
->orWhere('ou','not_contains', 'Production')
->sortBy('ou', 'asc')
->get();
foreach ($results as $result) {
dump ($result->ou);
}
The page displays the dump correctly. All is fine.
Not working stuff (yields error code listed above).
Route calling a Controller...
Route :
Route::get('newuser', 'UserCreationController#GetUserOrganizationalUnits');
Controller :
public function GetUserOrganizationalUnits()
{
$results = Adldap::search()->where('ou', 'ends_with', ' Users')
->orWhere('ou','not_contains', 'Production')
->sortBy('ou', 'asc')
->get();
return view('newuserform',compact('results'));
}
Why is it working from the web php with the routes directly but not from the called Controller?
I already try adding explicitely the following as well...
use Adldap\Contracts\AdldapInterface;
The facade is declared and it works in the web routes without even calling this...
Can you please help ?
Thanks.
I think you forgot to include the Facade
Add: use Adldap; in your UserCreationController.php
You'll also need to have this in your UserCreationController to get this working with the "use Adldap\Contracts\AdldapInterface;" approach:
protected $adldap;
public function __construct(AdldapInterface $adldap)
{
$this->adldap = $adldap;
}
Or implement the facade in your config/app.php:
'Adldap' => Adldap\Laravel\Facades\Adldap::class
I installed Mailgun for Laravel. I then tried to run the example
$data = [];
Mailgun::send('emails.welcome', $data, function($message)
{
$message->to('foo#example.com', 'John Smith')->subject('Welcome!');
});
But I got the following error:
"Argument 1 passed to Bogardo\\Mailgun\\Mailgun::__construct() must be an instance of Illuminate\\View\\Environment, instance of Illuminate\\View\\Factory given, called in /Users/koushatalebian/CLG/CL2G/app/vendor/bogardo/mailgun/src/Bogardo/Mailgun/MailgunServiceProvider.php on line 33 and defined"
What is going on?
If you are using Laravel 4.2, Please use Illuminate\View\Factory instead of Illuminate\View\Environment.
Bogardo mail gun package pointing wrong file.
/Users/koushatalebian/CLG/CL2G/app/vendor/bogardo/mailgun/src/Bogardo/Mailgun/MailgunServiceProvider.php
View / Pagination Environment Renamed
If you are directly referencing the Illuminate\View\Environment class or
Illuminate\Pagination\Environment class, update your code to reference Illuminate\View\Factory and
Illuminate\Pagination\Factory instead. These two classes have been renamed to better reflect their
function.
Edit:
You can use the correct class by editing the following file:
vendor/bogardo/mailgun/src/Bogardo/Mailgun/Mailgun.php
in Line 5:
remove use Illuminate\View\Environment; and use use Illuminate\View\Factory;
in line 53:
remove
public function __construct(Environment $views)
{
$this->views = $views;
}
use
public function __construct(Factory $views)
{
$this->views = $views;
}
Hope this will fix.