How to remove empty lines in my console Laravel 5.3 - laravel

I have a laravel installation, the console was working fine at start, then after a while i must have done something that made the console spit some extra empty lines. Here is what it looks like
D:\PATH_TO_MYAPP>php artisan migrate:refresh --seed
Migration table not found.
Migration table created successfully.
...
How do i remove these extra lines?

Check your artisan file at the project root and look at the very top. Are there any blank lines before the <?php tags? If so, remove them. Now check at the bottom of the file. Are you closing the php tag with ?>? If so, remove the ?>, you don't need them and any new line that comes after that is going to the console for output.

Related

Laravel Localization does not return translated string

I can't seem to figure out what I'm doing wrong.
I want my application to use "np" as its default locale. So I change the locale key in config/app.php to 'np.' And when I check for the current location in my controller, it returns 'np', so it's working fine until here. Then I created a "np.json" file directly inside the lang directory, which has the following content:
{
"Candidate": "उम्मेदवार"
}
Now when I try to return the translated string using:
__('Candidate')
It returns "Candidate" instead of "उम्मेदवार", even if the current locale function still returns "np". So I ran the following commands trying to clear the cache.
php artisan optimize:clear
php artisan config:clear
php artisan cache:clear
But still, the issue persists.
You have to call the translations like <filename>.translation_string, and that file has be placed inside a folder with your language code.
In your case, create a folder inside lang called np, then place a translation file (example: mystrings.php) in it, so you have this file in a folder lang/np/mystrings.php.
Your trans file looks like
<?php
return [
'Candidate' => 'उम्मेदवार',
];
Now, you have to set the lang to your language np with app()->setLocale('np'); or you set it directly in your .env and now you can call
echo __('mystrings.Candidate');
to get your translation.
Hope it helps

artisan make:migration ignores subfolders? [duplicate]

This question already has answers here:
Laravel running migrations on "app/database/migrations" folder recursively
(15 answers)
Closed 2 years ago.
I am using Laravel 5.6 and and migration files inside database/migrations/ work when I call artisan migrate but migration files in subfolders like database/migrations/example are skipped.
Even artisan migrate:status does not show the subfolders.
How can I tell Laravel to also include migration files from subfolders?
vendor\laravel\framework\src\Illuminate\Database\Migrations\Migrator.php line 465
same line number since Laravel 5.7 I guess, there's this line:
return Str::endsWith($path, '.php') ? [$path] : $this->files->glob($path.'/*_*.php');
This looks for the root migrations path matching the *_*.php pattern. If it was **/*_*.php you would've accomplished what you wanted.
But, good news! It can be hacked! The method responsible for getting the paths:
vendor\laravel\framework\src\Illuminate\Database\Console\Migrations\BaseCommand.php line 19
says that the path argument you gave to the command, will not be sanitized, or modified,
if ($this->input->hasOption('path') && $this->option('path')) {
return collect($this->option('path'))->map(function ($path) {
return ! $this->usingRealPath()
? $this->laravel->basePath().'/'.$path
: $path;
})->all();
}
So, setting the path argument as database/migrations/** should enable you to recurse into subfolders.
php artisan migrate --path="database/migrations/**"
Note: Then, for every migrate[:*] command to work, you need to specify the --path attribute. I migrated and rolled back with the --path attribute, and it worked.
There's a method in ServiceProvider that can do that for you.
loadMigrationsFrom($paths)
You will need to call it in your AppServiceProvider in the boot method like so:
public function boot()
{
$paths = [your, custom, migration, directories];
$this->loadMigrationsFrom($paths);
}
After doing this, running php artisan migtate will take subdirectories in consideration.

Laravel envelope MIX_VAR displaying wrong value

I am trying to get ENV variable from JS in laravel, but the value is wrong.
To prevent duplicates I am using this syntax:
APP_ENV=development
MIX_APP_ENV="${APP_ENV}"
And in console.log(process.env.APP_ENV) it gives me ${APP_ENV} in browser. It doesn't matter if I remove the double quotes from ENV file.
I cleared cache and restarted NPM run watch.
Is there anything I am missing?

Laravel 5 doesn't read values from dot ENV files

I don't know if this question is relevant or not. LARAVEL 5 is still in developmental phase. I have pulled LARAVEL 5 after watching one of the Laracast video about new features in LARAVEL 5. I couldn't resist to wait for its formal release.
I named the local environment dot file as .env.local.php. But for some reason I am unable to get the the values from this dot file when using $_ENV['KEY'].
I am quite sure that I have configured the environment correctly. When doing $app->environment() shows the correct environment. Has it been changed in LARAVEL 5 the way we get the values from dot files or am I missing something ?
By default in environment.php file you have something like that:
if (file_exists(__DIR__.'/../.env'))
{
Dotenv::load(__DIR__.'/../');
}
so only .env file is being read (notice .env not .env.php - so you should rename your file - or you can add as 2nd parameter file name .env.php if you want). Any other environment files (.local.env) are not being read by default - you will need to load them manually.
If you don't have such code by default, you should probably update/install Laravel 5 again (changes appear very often)
Now, I don't know what method you use, but you can put in your .env file also your environment name in for example APP_ENV variable, create .local.env file with content you want and then you could use in environment.php file:
if (file_exists(__DIR__.'/../.env'))
{
Dotenv::load(__DIR__.'/../');
if (getenv('APP_ENV') && file_exists(__DIR__.'/../.' .getenv('APP_ENV') .'.env')) {
echo "loading";
Dotenv::load(__DIR__ . '/../', '.' . getenv('APP_ENV') . '.env');
}
}
If you don't want to do it this way, you can probably change the other and load env file you want based on $env assuming you use PC based environment detection.
If it's unclear you can also look at What's the correct way to set ENV variables in Laravel 5?

PHPStorm: Syntax Highlighting for PHP code inside XML tags

Is there any way to make PHPStorm apply syntax highlighting to PHP code inside a tag in an XML file?
I'm working on an OpenCart project and I'm using Vqmod, which requires that I write PHP code in an XML file. For example:
<operation>
<search position="replace"><![CDATA[
<?php echo "123"; ?>
]]></search>
<add><![CDATA[
<?php echo "xyz"; ?>
]]></add>
</operation>
1) Settings | File Types -- assign *.xml (or whatever file name pattern you think is more appropriate) to PHP files entry (you may need to remove it from "XML files" first).
This will tell PhpStorm to treat such files as PHP (it's the only way to have PHP support).
The possible negative side -- it's an IDE-wide setting and will affect ALL such files in ALL projects. Therefore -- if you can name such files in some unique way (e.g. double extension: *.php.xml or *.xml.php; unique extension: *.pxml; unique file name ending: *layout.xml) then do it.
2) Settings | Template Data Languages -- find such files (or whole folder) and assign XML in 2nd column.
This will tell PhpStorm to treat such files as "PHP with XML" instead of default "PHP with HTML".
Official manual: http://confluence.jetbrains.com/display/PhpStorm/Syntax+highlighting+of+PHP+inside+JavaScript+%28and+other+languages%29

Resources