I have two classes in the services layer
CashTransactionServices.php
namespace App\Services\Cash;
use App\Models\Cash\CashTransaction;
use App\Models\Cash\CashBoxTransaction;
use DB;
class CashTransactionServices {
protected $AccountingAPI;
public function __construct(AccountingAPI $acc) {
$this->AccountingAPI = $acc;
}
CashBoxTransactionServices.php
namespace App\Services\Cash;
use App\Models\Cash\CashBoxTransaction;
class CashBoxTransactionServices extends CashTransactionServices {}
and in the controller
namespace App\Http\Controllers\Cash;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Services\Cash\CashBoxTransactionServices;
class CashBoxTransactionController extends Controller {
//
private $services;
public function __construct(CashBoxTransactionServices $cash_box_transaction_services) {
$this->services = $cash_box_transaction_services;
}
I have this error
ReflectionException: Class App\Services\Cash\CashBoxTransactionServices does not exist in file C:\xampp\htdocs\easyerp\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 826
I made sure of using the right namespaces and the right classes names!
PS: when I remove the inheretance from CashBoxTransactionServices class It works!
Related
I've encountered an error when refactoring my Laravel tests by adding at setUp() method.
This works as expected:
<?php
namespace Tests\Feature;
use App\Models\Person;
use Tests\TestCase;
class MembershipTicketsTest extends TestCase
{
public function test_a_non_member_cannot_list_redeemable_events()
{
$user = Person::factory()->create();
$this->actingAs($user);
$this->get(route('event.index'))->assertStatus(302)->assertRedirect(route('membership.create'));
}
Where as this returns the error Unknown formatter "firstName":
<?php
namespace Tests\Feature;
use App\Models\Person;
use Tests\TestCase;
class MembershipTicketsTest extends TestCase
{
protected $user;
protected function setUp() : void
{
$this->user = Person::factory()->create();
}
public function test_a_non_member_cannot_list_redeemable_events()
{
$this->actingAs($this->user);
$this->get(route('event.index'))->assertStatus(302)->assertRedirect(route('membership.create'));
}
Every solution to this error I've found says to make sure that you have use Tests\TestCase; in your file, which I do.
I presume this means I cannot use factories in the setUp() method of a test in Laravel. Is this true, and why is it the case?
Could someone explain what wrong with this code and what should I do?
I have a CustomerManager.php file located in app\BusinessLogic\Managers folder:
<?php
namespace app\BusinessLogic\Managers;
class CustomerManager
{
public function putItem()
{
// some code
}
}
This class should be injected into RetailController.php
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Route;
use app\BusinessLogic\Managers;
class RetailController extends Controller
{
protected $customerManager;
public function __construct(CustomerManager $customerManager)
{
$this->customerManager = $customerManager;
}
}
But as result error appers:
Illuminate\Contracts\Container\BindingResolutionException
Target class [app\BusinessLogic\Managers\CustomerManager] does not exist.
I'm tries instance a class that extends Controller class
This is my Controller:
<?php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class SalaryController extends Controller
{
public function calculateTotalSalary($id)
{
return $this->render('resources/view.html.twig');
}
}
and this is where I want to call the controller
<?php
namespace AppBundle\Tests\Units\Controller\Controller;
use AppBundle\Controller\SalaryController;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class SalaryControllerTest extends KernelTestCase
{
public function testExample()
{
$controller = new SalaryController;
$controller->calculateTotalSalary(1);
}
}
When executed the code give me this:
Starting test 'AppBundle\Tests\Units\Controller\Controller\SalaryControllerTest::testExample'.
PHP Fatal error: Call to a member function get() on null \vendor
symfony\src\Symfony\Bundle\FrameworkBundle\Controller\Controller.php on line 176
Line 176 in Controller class:
return $this->container->get('templating')->renderResponse($view, $parameters, $response);
the $container variable is null, Why ?
UI Code: in resources\views\DistributorRegistration.php
<?php
class DistributorRegitrationForm
{
public function distributorRegitrationFormHtml(){
return '<h1>Hello</h1>';
}
}
?>
In Controler Class.....
namespace App\Http\Controllers;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use resources\views\DistributorRegistration;
class DistributorRegistration extends Controller
{
function VestigePOS_GRNHandler(Request $request){
$id = $request->input('id');
return view(DistributorRegitrationForm::distributorRegitrationFormHtml()) ;
}
}
When I call this controller in routes
Fatal error: Class 'App\Http\Controllers\DistributorRegitrationForm' not found
Which file contains the class DistributorRegitrationForm? I'm missing an use App\...\DistributorRegitrationForm; in the controller, if it's not in the same namespace.
Calling DistributorRegitrationForm::distributorRegitrationFormHtml() won't work, unless the method becomes a static method (public static function).
You have some typos in there ;-)
I am getting the following error:
The autoloader expected class "Acme\HelloBundle\Controller\HelloController" to be defined in file "/var/www/Symfony/app/../src/Acme/HelloBundle/Controller/HelloController.php". The file was found but the class was not in it, the class name or namespace probably has a typo.
The controller code I have is actually:
namespace Acme\HelloBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
class HelloController
{
public function indexAction($name)
{
return new Response('<html><body>Hello '.$name.'!</body></html>');
}
}
any idea why this is?
<?php namespace Acme\HelloBundle\Controller;
....
Just add the "*LESS_THAN*"?php tag at the beginning. Try if works.
Your controller should extend Symfony\Bundle\FrameworkBundle\Controller\Controller
namespace Acme\HelloBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
use namespace Acme\HelloBundle\Controller;
class HelloController extends Controller
{
public function indexAction($name)
{
return new Response('<html><body>Hello '.$name.'!</body></html>');
}
}