php - Laravel Artisan command - "Class not found"

123

Ok, i've got some voodoo magic here. inb4 - I've made composer dump and dump-autoload 100 000 times.

<?
namespace Cds\Goods\Classes;

use Cds\Goods\Classes\Logs;
use Cds\Goods\Classes\AttributeUniteFront;

class ShiptorSync extends Shiptor{

    public static function sync_products() {    
        Logs::add_to_log("shiptor_sync", date("d.m.Y"), "begin sync shiptor products");
        $name = AttributeUniteFront::getSlugProduct($item->cds_products_id);
    }
}

Here is my class which function sync_products() I'm calling in console command, like that

<?php
​
namespace App\Console\Commands;
​
use Cds\Goods\Classes\ShiptorSync;
use Illuminate\Console\Command;
​
/**
 * Class ShiptorSynchronizeProducts
 */
class ShiptorSynchronizeProducts extends Command
{
  /**
   * The name and signature of the console command.
   *
   * @var string
   */
  protected $signature = 'shiptor:products:synchronize';
​
  /**
   * The console command description.
   *
   * @var string
   */
  protected $description = 'Sync goods';
​
  /**
   * Execute the console command.
   */
  public function handle()
  {
    ShiptorSync::sync_products();
  }
}

And everytime when i run it from console - Class 'Cds\Goods\Classes\AttributeUniteFront' not found

But! Class Logs found succesfully. What the heck...

enter image description here

Class is at his place

AttributeFront got right namespace enter image description here

And even in IDE it paints with a grey font and error like it is unused on page. What can it be????

enter image description here

enter image description here

No, really what the hell is this? It told that class not found and throws me full listing of not-founded class in error!!!

enter image description here

214

Answer

Solution:

Add to command controller:

 public function __construct()
    {
        parent::__construct();
    }

In Kernel.php:

protected $commands = [
        //
        '\App\Console\Commands\ShiptorSynchronizeProducts',
    ];

Then, why not just handle() the sync_products in the command? Also, $item does not appear to be defined.

Add this to the command file:

    use Cds\Goods\Classes\Logs;
    use Cds\Goods\Classes\AttributeUniteFront;

public function handle()
  {
    Logs::add_to_log("shiptor_sync", date("d.m.Y"), "begin sync shiptor products");
        $name = AttributeUniteFront::getSlugProduct($item->cds_products_id);
  }
}
900

Answer

Solution:

Gosh, i dunno why but the case was in opening short PHP tag, although short_open_tag is enabled. However i change it and everything works.

People are also looking for solutions to the problem: php - MPDF not supporting image/icon rotation

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.