Laravel Asset Pipeline Concatenates Assets in Local Environment - php

I've logged an issue about this in GitHub.
I've confirmed that my Laravel environment is set to local, but the asset pipeline still concatenates all of my assets into my two application.js and application.css files.
Has anyone else run into this in Laravel 4.2?

To fix this, I needed to remove local from the concat setting in the codesleeve config file.
'concat' => array('production', 'local'),
should be
'concat' => array('production'),
I think most developers would, by default, prefer not to concatenate files in development mode, which is I think where the confusion came from.

Related

Getting nginx environment variable in laravel with cached config

I use laravel framework on 2 websites,
The application backend is one, but view paths is different for each site.
There is nginx variable "WEBSITE", which is available in PHP (phpinfo prints it).
When I run application locally, all is right. But in production, I get exception what variable is not exists.
I discovered what during deploy running command php artisan config:cache, which cached all config in "bootstrap" directory. I don't may delete this command, because it ups performance of site. This command caches all config including app/config/view.php file that descript changes in view paths, like this
'paths' => [
resource_path('views/' . env('WEBSITE')),
],
but config already cached without variable and in this form is delivered to the production.
I don't understand how fix this problem, other that edit all views, base layouts for both sites. Does anyone know how to solve this problem in a simple way?
Just add a fallback by explicitly adding WEBSITE=somewebsiteurl in your production sites .env, then re-cache the config and try if it works.

Symfony 5 global dynamic configuration file

I'm a long time Zend Framework user (now renamed Laminas). But I decided to give a try to last Symfony version. So I just installed it in 5.1.2.
I'm facing a question regarding the multiple environments deployments. In my compay, we have :
Local environment which is developer pc.
Development.
Staging.
Production.
In ZF-Laminas, we have a global.php file which is located in config directory.
For those of you who are not familiar with this framework, you can override key set in global.php file by creating local.php file.
In this global file, I use to put standard configuration for my application.
For example (prod) :
'open_id' => [
'client_id' => 1234
]
Then, I have development and staging files which car override those values for every environmenet. During the deployment, the file corresponding to the environment is copied to local.php.
Let's say staging.local.php.dist becomes local.php with :
'open_id' => [
'client_id' => 5678
]
Which is fine because value is overriding the one from global file.
I would like the same behavior in Symfony but I don't see something similar in Symfony 5.
So far, I only found two possibilities
Create a bundle which will allow me to have a <bundle_name>.yaml file in config/packages directory. According to the documentation (https://symfony.com/doc/current/configuration.html#configuration-files), I will be able to have dev, prod and staging overrides. But it forces me to create a bundle to handle just some standard configurations, which is huge.
Use .env files. But .env files only allow string data, not complex data like arrays.
What do I miss ? Or is it my "zend" way of doing things that is wrong ?
Thanks.
You can also create services_%env%.yaml (services_dev.yaml, services_test.yaml) files for each environment. It will allow you to define different parameters and override/define services for each environment.
Example:
config/services_dev.yaml
parameters:
hello: 'world'
From what I understand from your post, your goal is to have different config values based on the server you are on. If this is the case, you can use environment variables (in the .env file or .env.local for server specific config). You can then use these values in your applications by binding the env var to a parameter. This parameter will then be available within the configuration by using %parameter_name% as value or within the container. You can also pas parameters to services (service definitions are handled the same way as any other config). For more information you can checkout these sources:
https://symfony.com/doc/current/configuration/env_var_processors.html
https://symfony.com/doc/current/configuration.html

Laravel 5 configuration - environments and overriding

I installed fresh Laravel 5 copy.
My detectEnvironment function is defined this way:
$app->detectEnvironment(function()
{
return 'local';
return getenv('APP_ENV') ?: 'production';
});
In config\local I've created database.php file:
<?php
return [
'nothing' => 'new',
];
I run php artisan clear-compiled.
My index method of WelcomeController is defined this way:
public function index(Application $app)
{
echo $app->environment();
var_dump($app['config']['database']);
//echo $app['config']['database'];
return view('welcome');
}
Application was imported this way: use Illuminate\Foundation\Application;
The result I get is:
local array(1) { ["nothing"]=> string(3) "new" }
whereas I would expect Laravel to cascade config file with production one (with the default config\database.php file.
The strange thing is that even if I comment the line return 'local'; run again php artisan clear-compiled it shows:
production array(1) { ["nothing"]=> string(3) "new" }
so it seems it always loads database.php file content (this one from local folder) and overrides main database.php file. It works fine again when I change this file name to for example aaa.php.
Is it a bug or maybe environment configuration shouldn't be stored inside config directory? But if not, where should they be store? I don't know if it's a bug or a feature so if anyone knows more about it, please give me a clue.
Although in documentation for Laravel dev (5.0) there is info that configuration will cascade it's not true. I have tested it about 2 weeks ago and it seems at the moment the only way to have different values for environments is using ENV file where you put custom values for current environment. Putting settings in directories won't work as it used to work however it's possible it will change or maybe has been already changed for last 2 weeks.
There's a package that brings the cascading config system back to Laravel 5.
Disclaimer: I am the author.
For me it looks like defect in Laravel 5 dev branch. I was able to work around by adding manual environment detection and configuration. This code does it.
'default' => $app->environment()=='testing'?'sqlite':'mysql',
It is easy to configure Laravel 5 environment.
Open your root application folder and find ".env.example",
Copy and rename into ".env",
Please fit ".env" file into your environment,
If you use GIT, make sure you don't push this file to your GIT repository.
For 'complete explanation', I write this configuration here.
Edited;
I quote from the developer in His github repository readme.md file;
phpdotenv is made for development environments, and generally should
not be used in production. In production, the actual environment
variables should be set so that there is no overhead of loading the
.env file on each request. This can be achieved via an automated
deployment process with tools like Vagrant, chef, or Puppet, or can be
set manually with cloud hosts like Pagodabox and Heroku.
So, you need to create ".env" file per machine and don't use ".env" file in your production server.

Laravel and Github - Workflow and Problems

I have a Laravel project right now and I'm using Github for my project.
I have two branches, master and develop.
The problem right now is,...
I have all the files in one folder /dev I'm using Sublime Text 2 and the official Github Client. When I switch branches, I see that in ST2 in the status bar, that's fine.
I put sftp-config.json in my gitignore BUT I have different FTP data for master and develop. I always have to edit the data in ST2 tu upload correctly onto my FTP to test my changes. Sometimes I even forget that, and accidentally upload develop to my master/live page.
Same problem for the routes.php, I need to disable SSL in my routes.php for the DEV because I do not have a wildcard certificate and my dev branches/ftp runs on dev.domain.tld and my main site at www.domain.tld .
I created a environment for my Laravel configs, one main config and "development" config.
Is it possible to use Config::get('app.ssl') in my routes.php in my filter? Like that:
Route::group(['before' => ['csrf',Config::get('app.ssl')]], function () {
Route::get('page', array('as' => 'page','uses' => 'PageController#getIndex'));
});
?
My workflow right now is very annoying and confusing sometimes. I always have to check that I do not upload stuff on my live server or changes the master files.
Any suggestions are highly appreciated!
Of course! Laravel supports environmental configuration out of the box. You can find pretty much everything you need in the official docs. However here's an example:
app/config/app.php - "main config"
array(
// other config entries
'ssl' => true
)
app/config/local/app.php - config for the environment local (you can call it whatever you want)
array(
'ssl' => false // here we override the value from our main config
)
Now the last thing we have to do is make sure our environments get detected correctly.
Laravel uses the host name to detect an environment. So you need to figure out how your machine(s) is called.
An easy way to do that is with the PHP function gethostname()
In bootstrap/start.php you can define your environments:
$env = $app->detectEnvironment(array(
'local' => array('your-machine-name'),
'other-environment' => array('other-machine-name')
));

Laravel Environment

I am very confused about the environment in Laravel 4.2. I have setup my environment folders in the /config folder. I then added the following:
$env = $app->detectEnvironment(array(
'production' => array('my-server-name'),
'local' => array('my-local-name')
));
where my-server-name and my-local-name where taken from the terminal by running hostname.
When I do this however, no matter where I run the code, the environment is always production. What am I doing wrong?
I think you're not using detectEnvironment correctly. In this function, YOU are supposed to return the environment used, based on a config file, or an external environment variable - not get the environment. If you look at the documentation, you'll see some samples on how to use detectEnvironment properly, with both config file, or external variable (e.g. set the environment variable MY_LARVEL_ENV=local at the command line, and access it using $_SERVER['MY_LARAVEL_ENV'] inside the function, to return the proper environment.
in the beginning of a project in laravel could be a really mess with the roots and all that stuff, so I recommend you to follow this tutorial!
https://github.com/JeffreyWay/Laravel-4-Generators
Go to the root of your project on cmd and follow the steps,once your ready, just type:
php artisan generate:scaffold theNameOfYourTable
And say yes!
It will create you all te MVC, Seeders,Standar of your project, and some other awesome staff. ;)

Categories