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
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 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 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 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 am using Laravel 5 to generate a PDF from a subscription generated from Cashier. The docs say this is as simple as calling:
return $user->downloadInvoice($invoice->id, [
'vendor' => 'Your Company',
'product' => 'Your Product',
]);
Unfortunately I'm getting an odd error:
No hint path defined for [cashier]
The code I am actually using is as follows:
Route::get('billing/invoices/download/{id}', function($id){
$user = Auth::user();
//$invoice = $user->invoices()->find($id);
return $user->downloadInvoice($id, [
'vendor' => 'Certify Me',
//'product' => $invoice->lines->data[0]['plan']->name,
'product' => 'Subscription',
]);
});
The docs make me assume that the PDF is automatically generated. I'd then assume I could override the PDF layout if I chose to.
I just ran into this (L5.1, Cashier 6.0). This seems to be caused by the service provider not being correctly loaded.
Here is how I fixed it:
Check that you have added the correct service provider, at the time of writing that is Laravel\Cashier\CashierServiceProvider to your config/app.php
If it still doesn't work, go run php artisan config:clear to make sure that the service provider is picked up.
Happy invoicing!
I'm going to resurrect this beast.
I had a similar issue because the service provider was not loaded. If you checkout CashierServiceProvider you'll see it adds the necessary 'namespace' for the 'cashier' prefixed views.
public function boot()
{
$this->loadViewsFrom(__DIR__.'/../../views', 'cashier');
$this->publishes([
__DIR__.'/../../views' => base_path('resources/views/vendor/cashier'),
]);
}
Add Laravel\Cashier\CashierServiceProvider to your config/app.php file and inside the providers key.
For anyone who runs across this like we did.