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,
]);
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 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
I have one file inside config folder lets say: file1
File Location:
config/
---file1.php
I have following code in my file: file1.php
return [
'MASTER_KEY' => ['SUB_KEY1' => 'SOME_VALUE', 'SUB_KEY2' => 'SOME_VALUE', 'SUB_KEY3' => 'SOME_VALUE'],
];
How to access the value from MASTER_KEY of particular SUB_KEY?
Assuming for SUB_KEY2, Try -
config('file1.MASTER_KEY.SUB_KEY2')
Guide
In order to access that value you have 2 choices which are the same at the end:
first one: which use Config refers to the config facade.
use Config;
$myValue = Config::get('file1.MASTER_KEY.SUB_KEY1');
enter code here
second one: using config() helper function which uses Config facade and its only an alternative and easy way to use Config facade.
$myValue = config('file1.MASTER_KEY.SUB_KEY1');
use
config('file1.keyname');
if you have made any changes in config file then it might not work . so after changes in config file you have to run the following two commands .
php artisan config:cache
php artisan config:clear
Make a use Config; in your controller.
In config/file1.php
<?php return [
'ADMIN_NAME' => 'administrator',
'EMP_IMG_PATH' => '../uploads/profile/original',
'EMP_DOC_PATH' => '../uploads/profile/documents', ];
In controller
use Config;
$variable= Config::get('file1.EMP_DOC_PATH');
By this way you can get the variables value from config.
I think this will make something good.
I am using laravel 4 and I have created a file inside app/config as follows : The file name is aws.php
<?php
return [
'key' => 'xyz',
];
Now, from my controller I tried to access the key as follows :
$key = Config::get('aws.key');
but it returns null. How can I solve this problem ? I have googled it but have not found the solution.
You can access "key" by Config::get('aws.key');
but need to run this command: php artisan config:clear
try
$key = \Config::get('aws.key');
Config is not in the same namespace as class that call this facade, so You want to go to global namespace to search Config class