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!
Related
I'm trying to expose only some endpoints with API Platform as explained here: https://api-platform.com/docs/v2.7/core/operations/.
If I just use the ApiResource attribute, I get the expected result (i.e. the default CRUD endpoints).
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\MyclassRepository;
#[ORM\Entity(repositoryClass: MyclassRepository::class)]
#[ApiResource]
class Myclass
{
}
But none of the options to show only some operations work.
This one:
#[ApiResource(operations=[
new Get(),
new GetCollection()
])]
... just outputs "No operations defined in spec!" on /api/docs. It also makes VSCode angry about "operation=":
Expression is not writable.intelephense(1024)
Undefined constant 'App\Entity\operations'.intelephense(1011)
Syntax error: unexpected token '='PHP(PHP2014)
This one:
#[ApiResource(
operations: [
new Get(),
new GetCollection()
]
)]
... produces the error "Compile Error: Constant expression contains invalid operations".
The project is running locally on Docker php:8.0-fpm with "api-platform/core": "^2.7".
The appropriate "use" statements are present.
I tried different combinations of methods and config (e.g. uriTemplate).
I also tried using api-platform ^2.6 with :
#[ApiResource(
collectionOperations: ['get'],
itemOperations: ['get'],
)]
... which produces the error "Unknown named parameter $collectionOperations".
What am I missing?
Thanks!!
API Platform requires PHP 8.1, not 8.0. After upgrading, this works:
#[ApiResource(
operations: [
new Get(),
new GetCollection()
]
)]
In laravel 8 I create a new component with command :
php artisan make:component Frontend/Nomination
and I use it in my blade.php file as :
<x-frontend.nomination :defaultNomination="$defaultNomination" />
but as functionality has ajax requests I try to put some methods inside of this component and returning json
But adding line in routes/web.php:
Route::get('/get_nominated_photos/{nomination_id}/{current_page?}', View\Components\Frontend\Nomination::class)->name('get_nominated_photos');
I got error :
View\Components\Frontend\Nomination` was not found: Controller class `View\Components\Frontend\Nomination` for one of your routes was not found. Are you sure this controller exists and is imported correctly?
If there is a way to use Components in routes/web.php? If yes in which way ?
UPDATED BLOCK # :
looks like I set the path invalid : So I modified line :
Route::get('/get_nominated_photos/{nomination_id}/{current_page?}', \App\View\Components\Frontend\Nomination::class)->name('get_nominated_photos');
and in component file : app/View/Components/Frontend/Nomination.php
I have header :
<?php
namespace App\View\Components\Frontend;
class Nomination extends Component
{
...
But I got error :
Invalid route action: [App\View\Components\Frontend\Nomination].
at vendor/laravel/framework/src/Illuminate/Routing/RouteAction.php:92
88▕ */
89▕ protected static function makeInvokable($action)
90▕ {
91▕ if (! method_exists($action, '__invoke')) {
➜ 92▕ throw new UnexpectedValueException("Invalid route action: [{$action}].");
93▕ }
94▕
95▕ return $action.'#__invoke';
96▕ }
• `App\View\Components\Frontend\Nomination` was not found: Controller class `App\View\Components\Frontend\Nomination` for one of your routes was not found. Are you sure this controller exists and is imported correctly?
Thanks in advance!
As I said in the comment, you cannot render a Laravel Compoment that way unless your component doesn't have props and doesn't use slot.
The last release (v.8.80) of Laravel should help you achieve what you're trying to do with the pull #40425
Route::get(
'/get_nominated_photos/{nomination_id}/{current_page?}',
fn($nomination_id) => Blade::render('<x-frontend.nomination :defaultNomination="$defaultNomination" />', ['defaultNomination' => $nomination_id])
)->name('get_nominated_photos');
Is this possible in laravel 5?
public function attachable($type)
{
// sample: $type = 'SomeContent';
return $this->morphedByMany($type::class, 'message_attachable');
}
I am getting this error:
Dynamic class names are not allowed in compile-time ::class fetch
edit:
[2018-06-17 22:59:13] local.ERROR: Dynamic class names are not allowed in compile-time ::class fetch {"userId":1,"email":"system#gmail.com","exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalErrorException(code: 64): Dynamic class names are not allowed in compile-time ::class fetch at U:\\www\\prado247\\app\\Models\\Message\\Message.php:25)
[stacktrace]
#0 {main}
"}
You have to specify the classpath:
public function attachable($type)
{
// sample: $type = 'SomeContent';
return $this->morphedByMany('App\\'.$type, 'message_attachable');
}
Is type meant to be the string name of the class or is it an object of that instance? If it's an instance and you want to know which class it is an instance of you should use
return $this->morphedByMany(get_class($type), 'message_attachable');
You can read about the documentation of get_class in the PHP Docs but basically it returns the class of the instance as a string that Eloquent can use.
I have created a custom exception class in Laravel 5.2. It works well till laravel 5.4.
When Im trying to use the same custom exception class with laravel 5.5 it is throwing following error.
Type error: Argument 1 passed to App\Utility\Exceptions\CustomException::report() must be an instance of Exception, none given, called in /var/www/html/bubbles/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php on line 102 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Type error: Argument 1 passed to App\\Utility\\Exceptions\\CustomException::report() must be an instance of Exception, none given, called in /var/www/html/bubbles/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php on line 102 at /var/www/html/bubbles/app/Utility/Exceptions/CustomException.php:39)
Here is the custom exception class I've been using
<?php
namespace App\Utility\Exceptions;
use Illuminate\Support\Facades\Lang;
use Exception;
class CustomException extends Exception
{
private $error_code = NULL;
private $error_info = NULL;
function __construct($type = NULL, $errors = NULL)
{
$this->error_code = $type['error_code'];
$this->error_info = $errors;
$message = Lang::get('exceptions.'.$this->error_code);
parent::__construct($message, $type['code'], NULL);
}
public function report(Exception $exception)
{
parent::report($exception);
}
public function getErrorCode()
{
return $this->error_code;
}
public function getErrorInfo()
{
return $this->error_info;
}
}
// end of class CustomException
// end of file CustomException.php
Could anybody will explain me why it is throwing argument must be instance of exception ? Any help would be greatly appreciated.
My programming environment
PHP 7.0.1
Laravel 5.5
The exception handler in Laravel 5.5 checks if the exception has a report method, and if so, let the exception handle the reporting itself. This means that the handler will see your report method, and call $e->report();, but your report method requires a parameter.
This is done in Handler::report.
You either need to remove the parameter in your report method (it should be reporting itself; $this) if you want to use this functionality, or rename the method if you don't want Laravel to call it (and fail).
Relevant: Laravel 5.5 Adds Support for Custom Exception Reporting
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.