My route file
Route::model('rank', 'Rank');
Route::resource('rank', 'AdminRankController');
My Controller file
public function show($rank)
{
return $rank;
}
This give me error Symfony \ Component \ Debug \ Exception \ FatalErrorException
Maximum function nesting level of '100' reached, aborting!
Any Help will be appreciated . Earlier It was working . But My composer update ruined all.
Please note if I change it like
Route::model('ranks', 'Rank');
It is working but no database query runs to fetch the corresponding row
Related
I've installed laravel livewire on a Laravel 8 project, ad when i run the command php artisan make:livewire table the terminal shows this error:
ArgumentCountError
Too few arguments to function Illuminate\Support\Str::finish(), 1 passed in /Applications/MAMP/htdocs/cuoreLaravel/vendor/livewire/livewire/src/helpers.php on line 12 and exactly 2 expected
at vendor/laravel/framework/src/Illuminate/Support/Str.php:235
231▕ * #param string $value
232▕ * #param string $cap
233▕ * #return string
234▕ */
➜ 235▕ public static function finish($value, $cap)
236▕ {
237▕ $quoted = preg_quote($cap, '/');
238▕
239▕ return preg_replace('/(?:'.$quoted.')+$/u', '', $value).$cap;
+17 vendor frames
18 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
I've followed all the documentation installation steps, but I don't understand what the problem is.
I hope someone can help me :-) thanks
This happened to me after a fresh install of Livewire. Running php artisan optimize fixed it in my case. I have not found the exact reason, but I suspect some of the Livewire config needed to be included in the config cache first.
So either optimize, or clear the cached config completely.
I have used the following lines of code in my shopware 5 plugin
use HatslogicAbandonedCartNotification\Models\AbandonedCartItems as AbandonedCartItemsModel;
use HatslogicAbandonedCartNotification\Models\Repository as AbandonedCartItemsRepository;
I have a variable
/ **
* #var AbandonedCartItemsRepository
* /
private $abandonedCartItemsRepository;
In the function __construct I set the variable
$this->abandonedCartItemsRepository = $this->modelManager->getRepository (AbandonedCartItemsModel :: class);
But in PHPstan analysis I got the following error
Property HatslogicAbandonedCartNotification \ Subscriber \
CartNotification :: $ abandonedCartItemsRepository
(HatslogicAbandonedCartNotification \ Models \ Repository) does not accept Doctrine \ ORM \ EntityRepository.
Anything wrong with my code? or is it an ignorable error?
Thank you #Shyim
I have fixed the issue by
/** #var AbandonedCartItemsRepository $abandonedCartItemsRepository */
$abandonedCartItemsRepository = $this->modelManager->getRepository (AbandonedCartItemsModel :: class);
$this->abandonedCartItemsRepository = $abandonedCartItemsRepository;
Just assign it to a variable and make a phpdoc. That should fix it :)
Otherwise try the doctrine phpstan extension
I'm trying to mock the Cache::put() facade. But it gives me an error. I have tried different ways but couldn't figure it out.
public function testGetAllFromDatabase()
{
$industry = new Industry();
Cache::shouldReceive('has')
->once()
->with('industries.all')
->andReturn(false);
Cache::shouldReceive('put')
->with('industries.all', '', 0)
->andReturn(true);
$this->industryMock
->shouldReceive('all')
->once()
->andReturn(array_reverse($this->industries));
$this->app->instance(Industry::class, $this->industryMock);
$industryRepository = new IndustryRepository();
$all = $industryRepository->all();
dd($all);
$this->assertContains( $this->industries[2], $all);
}
But when I execute it the following error is occurring.
$ vendor/bin/phpunit
PHPUnit 7.2.7 by Sebastian Bergmann and contributors.
...E 4 / 4 (100%)
Time: 3.76 seconds, Memory: 12.00MB
There was 1 error:
1) Tests\Unit\RepositoriesTests\IndustryRepositoryTest::testGetAllFromDatabase
Mockery\Exception\NoMatchingExpectationException: No matching handler found for Mockery_1_Illuminate_Cache_CacheManager::put('industries.all', object(Illuminate\Database\Eloquent\Collection), '1440'). Either the method was unexpected or its arguments matched no expected argument list for this method
Objects: ( array (
'Illuminate\\Database\\Eloquent\\Collection' =>
array (
'class' => 'Illuminate\\Database\\Eloquent\\Collection',
'properties' =>
array (
),
),
))
F:\development\consulting.local\src\vendor\mockery\mockery\library\Mockery\ExpectationDirector.php:92
F:\development\consulting.local\src\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:223
F:\development\consulting.local\src\app\Repositories\IndustryRepository.php:30
F:\development\consulting.local\src\tests\Unit\RepositoriesTests\IndustryRepositoryTest.php:81
I have tried many ways but couldn't get it to fix. Thank you.
Since it may help others, Laravel's facade includes helper functions that allow swapping then with a Mockery test double
This means that when you use a shouldReceive you can chain it with any Mockery expectation for example in this case if you don't care about some parameters you can use:
Cache::shouldReceive('put')
->with('industries.all', \Mockery::any(), \Mockery::any())
->andReturn(true);
In case it helps others, it's good to point out that you may not want to mock Cache, but instead actually use the real Cache.
That's because it's a Cache for testing only:
When running tests via vendor/bin/phpunit, Laravel [....] automatically configures the session and cache to the array driver while testing, meaning no session or cache data will be persisted while testing.
https://laravel.com/docs/8.x/testing#environment
Note that unlike the OP's test, you may need to follow Laravel's guidance about your test class extending their TestCase to get the behavior, e.g.
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
Laravel Version: 5.6.16
PHP Version: 7.2.3
Database Driver & Version: N/A
Description:
laravel\framework\src\Illuminate\Container\Container.php public function getAlias($abstract)
throws ErrorException: Illegal offset type in isset or empty
when $abstract there is not in $this->aliases[]
$this->aliases[$abstract] is null and !isset($this->aliases[$abstract]) throws ErrorException: Illegal offset type in isset or empty
$abstract value is Modules\Administration\Tests\Commands\StubJsonCommandHandler
Steps To Reproduce:
Run AdministrationControllerTest (https://github.com/proyectotau/TAU/ clone laraveldusk branch [4ef9b0e124657abed7afde0969f332bf7be95a8b])
Is it a bug or I have any mistake? Thanks in advance!
When binding an instance to the container, please make sure you are using:
app()->instance('dependency', $instantiation);
not,
app()->bind('dependency', $instantiation); // DON'T bind an instance
Attempting to bind an instance will result an error, as the container tries to index possible aliases using a concrete object as opposed to a type.
Workaround
Change in getAlias() function
! isset($this->aliases[$abstract])
for
! isset($this->aliases[(string)$abstract])
Or change explicitly type-hint to string at ALL functions (#param string is not enough)
public function getAlias($abstract)
for
public function getAlias(string $abstract)
But it fails later in next use of [$abstract] in Container:
isShared() at isset($this->instances[(string)$abstract]) isset($this->bindings[(string)$abstract]
resolve() calling to$this->resolved[(string)$abstract] = true;
getConcrete() at if (isset($this->bindings[(string)$abstract]))
getContextualConcrete() at if (empty($this->abstractAliases[(string)$abstract]))
getExtenders() at if (isset($this->extenders[(string)$abstract]))
and in Illuminate\Foundation\Application:
make() at if (isset($this->deferredServices[(string)$abstract]) && ! isset($this->instances[(string)$abstract]))
PS: Please have a look to Alvaro Gonzalez's comment in
php - How do I fix this illegal offset type error
I finally found out the issue was send params like ::class which can not be used as an array index.
Strings must be instead
I am just trying to plant AJAX Chat for my website users. I have successfully completed the installation process with database configuration. But when I am trying to brows the domain.com/ajaxchat/index.php its returning this error given below:
XML Parsing Error: junk after document element Location: http://futurenext.esy.es/inc/chat/ Line Number 2, Column 1:
I think that the problem is in AJAXChatTemplate.php , and here the code is:
function getContent() {
if(!$this->_content) {
$this->_content = AJAXChatFileSystem::getFileContents($this->_templateFile);
}
return $this->_content;
And the error message is like:
" Non-static method AJAXChatFileSystem::getFileContents() should not be called statically, assuming $this from incompatible context in line 37"
Now please any one can help me to fix the problem. What is the problem here I can't really understand. Thanks.