i tried every method to resolve this, like clear cache,composer update/install, but after php artisan config:cache, it appears again.
In config.php line 839:
Call to undefined method Illuminate\Validation\Rules\In::__set_state()
and whole page turns to blank page.
In bootstrap/cache/config.php file it shows:
'environment' =>
array (
'form' =>
array (
'rules' =>
array (
'app_name' => 'required|string|max:50',
'environment' => 'required|string|max:50',
'environment_custom' => 'required_if:environment,other|max:50',
'app_debug' =>
array (
0 => 'required',
1 =>
Illuminate\Validation\Rules\In::__set_state(array(
'rule' => 'in',
'values' =>
array (
0 => 'true',
1 => 'false',
),
)),
),
I also got this error because instead of
"Illuminate\Validation\Rule"
I have put
"Illuminate\Contracts\Validation\Rule"
This is issue with laravel/framework/src/Illuminate/Validation package.
Here inside Rules folder, we have class named In (file In.php)
It is missing function __set_state .
If you will add following function in this class,
static public function __set_state($array = []){
return 'boolean';
}
The problem will be resolved. Also, it is temporary solution ( composer install/update command can remove your function)
Enjoy...
I think you have some config file with validation rules. Verify if you have config/environment.php file or verify other configuration files.
I think in one of them you have:
Rule::in([true, false]);
You shouldn't use this syntax in configuration files because it cannot be cached, instead you should use:
'in:1,0'
However it seems to be quite strange to keep any validation rules in configuration files.
just delete file config.php
from bootstrap/cache/
and than run
command composer dumpautoload
than
php artisan config:cache
it work for me
Add this code:
use Illuminate\Validation\Rule;
Changing Rule::in([true, false]); with 'in:1,0' worked for me. I needed to remove all strange references to Rule class inside bootstrap/cache/config.php too.
just delete file
config.php
from
bootstrap/cache/
and than run command composer dumpautoload
than php artisan config:cache
Related
I have made a config test.php
return [
'name' => 'Testname',
'street' => 'Teststraße',
'street_number' => '69',
'zip' => '42077',
'city' => 'Winterfell',
'telephone' => '0123456789',
'email' => 'hsw#hsw.hsw'
];
created a ConfigServiceProvider:
public function register()
{
config([
'config/test.php'
]);
}
but in my test.blade.php I can access the contents only via
{{config('test.0.name')}}
There has got to be a better, easier way for this right? The data is supposed to be used in multiple blades. Yet the ".0." feels so unnecessary.
I am new to PHP and Laravel, and I am using PHP 8.1 and Laravel 9.14.
Thanks in advance!
#######################
Edit: In my case I had the problem, that my cache wasn't cleared "php artisan config:cache" thanks to #matheenulla for hinting at that!. Thats why I tried the route with the ServiceProvider. I hope this may help someone in the future!
You don't need to create a service provider to use your config, unless you want it to be in some other location (in case you are creating a custom Laravel package), so you may delete your ConfigServiceProvider. In fact, you're just using config wrong:
{{config('test.0.name')}}
should be:
{{config('test.name')}}
I'm writing a package on laravel that it require some packages to install.
I want to overwrite own package configuration file with the applications's published copy, and use the mergeConfigFrom method within my package service provider's register method. but it dosent work as i expect
app/config/publishedConfig.php
return [
'dashboard_url' => 'home',
'logout_url' => 'logout',
'login_url' => 'login'
];
And
package/vendor/path/to/config/config.php
return [
'dashboard_url' => 'dashboard/login',
'logout_url' => 'dashboard/logout',
'login_url' => 'mongodb-login'
]
Then in register method on my package service provider i use mergeConfigFrom like below to overwrite publishedConfig on run time:
public function register(){
$this->mergeConfigFrom(
__DIR__.'/config/adminlte-logo.php','publishedConfig'
);
}
After that I use dd(config('publishedConfig')) helper to get result of merge But the result not changed.
expected result is :
'dashboard_url' => 'dashboard/login',
'logout_url' => 'dashboard/logout',
'login_url' => 'mongodb-login'
I will appreciate anyone who solve my issue.
Thanks in advance
Finally i have overwrite it in --force tag way.
php artisan vendor:publish --tag=config --force
I need a little help please :
With Laravel migrations, I like to put the migration in subfolder.
in a testing class, this works :
$this->artisan('migrate:fresh');
But, this does not work :
$this->artisan('migrate:fresh --path=/database/migrations/v1');
Do you have the solution please to specify the path with the tests?
Thank you.
The artisan method takes two parameters ($command, $parameters = []).
To get this to work you'll need to put the options in the parameters array:
$this->artisan('migrate:fresh', [
'--path' => 'database/migrations/v1'
]);
Just an FYI, the same is also true for command arguments e.g.
php artisan make:model Product -m
would be
$this->artisan('make:model', [
'name' => 'Product',
'-m' => true,
]);
I am trying to work with fluidxml to test if I can use it, but I cant get it to start working, I am using codeigniter framework. I cloned the repo https://github.com/servo-php/fluidxml and added it to a folder I created called thirdparty. Then here is the code for the function
public function xmltrial(){
$this->load->helper('file');
require_once(APPPATH.'third_party/fluidxml/source/FluidXml.php');
$book = new FluidXml();
$book->add([ 'title' => 'The Theory Of Everything',
'author' => 'S. Hawking',
'chapters' => [
[ 'chapter' => [
'#id' => '1',
'#' => 'Ideas About The Universe' ] ],
[ 'chapter' => [
'#id' => '2',
'#' => 'The Expanding Universe' ] ],
]]);
echo $book;
}
So I am getting two errors , one is Fatal error: Class 'FluidXml' not found even and the second one is if I use use function \FluidXml\fluidxml;
use function \FluidXml\fluidns;
use function \FluidXml\fluidify; all this character inside my xmltrial function it shows a red error on them.
You should use composer to manage your dependencies. Get composer installed, then install FluidXml into the vendor folder by typing
composer require servo/fluidxml
in the command line. Then you can
require_once 'vendor/autoload.php'
in your index.php, and you can forget about having to require in the files! You just need to put the relevant use statement under your namespace declaration.In your case,
use FluidXml\FluidXml;
Now you can start calling your class!
See Packagist for composer package details https://packagist.org/packages/servo/fluidxml
See Composer site to get composer into CodeIgniter if you don't already https://getcomposer.org/
I need to set admin email in many place. so I created constants.php in config folder.
<?php
return array(
'admin_email' =>'joe#doe.com',
'admin_name' =>'Admin',
);
I was able to access this in my routes.php
dd(Config::get('constants.admin_email'));
However, when I try to access it in mail.php by
'from' => [
'address' => Config::get('constants.admin_email'),
'name' => Config::get('constants.admin_name')
],
I got Class 'Config' not found in mail.php.
Any suggestions? Thanks.
After some testing, I've found you can't use Config, \Config or config() in any files in your config folder. I believe they are not available to any of these files, but I'm not 100% sure why this is.
Regardless, to solve this issue and still have them available in other parts of your application, use env or environment variables. In your .env file, add the following:
ADMIN_EMAIL=joe#doe.com
ADMIN_NAME=Admin
Then, in your mail.php and anywhere else you want to use them, access them using:
'from' => [
'address' => env('ADMIN_EMAIL'),
'name' => env('ADMIN_NAME')
],
You can actually see them already in use in your mail.php and other config files, so it makes sense to use what already works. Hope that helps!
Use
config('constants.admin_email');