Categories
Fixing Stuff Laravel Samuel

Fixing mix-manifest Error

If you are working in WordPress and see the error message:

Warning: file_get_contents(/file-path/build/mix-manifest.json): failed to open stream: No such file or directory

You can fix this error message with the steps below:

From the root of your project open up the command line and type:

npm install

npm run dev

This will create the build file and the mix-manifest file, and your error should go away.

If you are working in Laravel and see the error message:

The mix manifest does not exist. View:/var/www/html/site-name/resources/views/layouts/app.blad.php

You can fix this with the exact same steps that are listed above πŸ™‚

Categories
Laravel Samuel

Another Laravel 5.5 -> 6.0 Upgrade

First Error:

When trying to save information on the user profile page, we are getting an error if any of the fields are left blank.

Fix:

In App -> Http -> Kernel.php line 22 we will comment out this:

       /* comment this out because its causing errors anytime someone submits a form with an empty value
        \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
       end comment */

Second Error:

Once on Laravel 6.0 we needed to jump our version of php because the site would not load with our old version of php 7.2 running. We asked valet to use @php7.4 which caused this error message:

Brew was unable to install [php@7.4]

To Fix:

brew update
brew upgrade php
composer global update
valet install
valet use php@7.4
composer global update

*note if the latest version of valet did not come installed with support for php 7.4 (it did, but if it didn’t) then we could have edited this file:

code ~/.composer/vendor/laravel/valet/cli/Valet/Brew.php

class Brew
{
    const SUPPORTED_PHP_VERSIONS = [
        'php',
        'php@7.4',
        'php@7.3',
        'php@7.2',
        'php@7.1',
        'php@7.0',
        'php@5.6',
        'php73',
        'php72',
        'php71',
        'php70',
        'php56'
    ];

*just add php 7.4 to the top of the list, or whatever version of php you need valet to support.

First Error On Staging Site:

When trying to submit a form we get this error message of “undefined index:secret”

Fix:

Double check that the file config -> services.php has the SparkPost varialbes setup correctly, they should be:

 'sparkpost' => [
        'secret' => env('SPARKPOST_SECRET'),

        // optional guzzle specific configuration
        'guzzle' => [
            'verify' => true,
            'decode_content' => true,

    ],

    'options' => [
    // configure endpoint, if not default
    'endpoint' => env('SPARKPOST_ENDPOINT'),

    // optional Sparkpost API options go here
    'return_path' => 'SendingEmail@verifieddomain.com',
    'options' => [
        'open_tracking' => false,
        'click_tracking' => false,
        'transactional' => true,
    ],
   ],
  ],

*You can also see the full list of install tips and config tips for the package here: https://github.com/vemcogroup/laravel-sparkpost-driver

Categories
Laravel Samuel

Upgrading Laravel From 5.6 -> 5.7 -> 5.8 -> 6.0

This post is going to go through upgrading a site currently running Laravel 5.6. We will be taking the site up from 5.6 to 5.7 with the goal of eventually going all the way to 6.0 (the latest LTS at the time of this writing).

Start by creating a new upgrade branch from the dev branch:

git checkout -b feature/upgrading-laravel dev

*please note we are pulling from the dev branch here because the dev branch is currently more up to date than the master branch. We are writing these Laravel upgrades during a single day upgrade process, taking a Laravel site from 5.5 all the way up to 6.0. So if you are following along this series updating your own site make sure to branch off of whatever your current branch is (which will most likely be master)

The next thing we are going to do is open up sourcetree and push our newly created feature branch up to the remote repo server. To do this we will hit the push button and then check the box for the new branch and hit push.

Now that we have our new feature branch to the remote repo, were going to login to Laravel shift and purchase the shift we need, in this case we will be purchasing a shift from 5.6 -> 5.7. When we purchase the shift we will input our new feature branch as the branch shift should use to update from. In the Shift Screen there will be 2 boxes and we will need to fill them in this:

username/repo-name branch-name

With our shift purchased and executed, its time to merge the new branch shift creates into our updating branch and check how the site is doing locally:

Git fetch origin
Git checkout shift-42238
Git checkout feature/upgrading-laravel
Git merge shift-42238

Before we view the site locally we will also want to run:

composer update
php artisan cache:clear
php artisan route:clear
php artisan view:clear
php artisan config:clear

Issues with cache:clear:
*If the artisan cache:clear line fails due to permissions issue, then do the following to fix that error:

Check to see if the data folder is present at: 
storage/framework/cache/data

Create the data directory manually if its not there: (storage/framework/cache/data)

run php artisan route:clear again and it should work :)

--update --
If creating the data folder still does not fix the issue, then try running:

php artisan config:cache 

If there are any bugs we will fix those, in this case we did not have any issues so we will go ahead and merge our branch into the dev branch and test it on the staging server.

git checkout dev
git merge --no-ff feature/upgrading-laravel -m "merge laravel 5.7 into dev"

*we can either then git push dev from the command line, or we can use sourcetree to push the dev branch up to the remote server, and deploy to the staging site from there.

Once logged into our staging server we will run our deployment script, and then navigate to the project root folder and run the following commands:

composer update
php artisan cache:clear
php artisan route:clear
php artisan view:clear

*one special note, if the server has any issue running composer update, we can always delete the vendor directory and then run composer install which will install a fresh version of all dependencies. The fastest way to delete the vendor folder is via command line with:

rm -rf vendor

Fixing Issues:

#1: A Note From Shift: Laravel 5.8 changed several of the core contracts with new implementations and methods. You should review the Upgrade Guide for more detail on these respective changes:

Shift found references to these contracts within:

  • app/Excel/Exports/InquiryExport.php

Error Message On Staging Server Command Line:

In CustomFormBuilderServiceProvider.php line 9:

Interface 'Illuminate\Contracts\Support\DeferrableProvider' not found

In CustomFormBuilderServiceProvider.php line 9:

Interface 'Illuminate\Contracts\Support\DeferrableProvider' not found

To fix this issue we just updated the packages in composer.json to work with the latest version of Laravel. This was tricky as composer was not able to resolve the packages into an installable set, so what we did is removed all of the packages and then added them back into the file in small chunks and ran composer each time, until we arrived at the full set of needed packages.

Error #2:

The file TrustProxies.php was causing an error message to display in the command line, to fix this we changed the code in this file to:

protected $headers = Request::HEADER_X_FORWARDED_ALL;

Error #3:

Now we were at the point where we could actually pull the website up, but we received the following error screen on any page of the site:

To Fix this issue we went to the file referenced in the error message (configure_vehicle.blade.php) and we updated the code to:

OLD: 
-    var base_url = "{{ route('configurator.configure_vehicle', ['manufacturer' => $manufacturer->slug, 'vehicle' => $vehicle->slug]) }}";

New:   var base_url = "{{ route('configurator.configure_vehicle', ['manufacturer_slug' => $manufacturer->slug, 'vehicle_slug' => $vehicle->slug]) }}";

The latest version of Laravel needs these values to be explicitly defined.

Error #4

Once we try to login to the site we are getting the error:

To fix this we will update our call in AuthAdminiter.php to be:

$this->authenticate($request, $guards);

Error #5

Once we got the login permission issue fixed, we were then presented with this error screen:

If we look at the error we can pull out a few clues:

Missing required parameters for [Route: packages.create_for_vehicle] 
[URI: manage/packages/create/vehicle={vehicle_id}]. 
(View:C:\wamp64\www\SFPS\resources\views\vehicles\partials\table.blade.php)

The route mentioned in the error wants you to pass vehicle_id, but the code as-is is only passing in id so Laravel can’t figure that out. To fix this we can either rename it, or remove the special key. ([$vehicle->id]  or [‘vehicle_id’=>$vehicle->id]). So in our case we made the following update to fix the bug:

Old: 
<td>{{ Helper::number(count($vehicle->packages)) }} {!! link_to_route('packages.create_for_vehicle', 'Add', ['id' => $vehicle->id], ['class' => 'btn btn-primary']) !!}</td>

New:         
<td>{{ Helper::number(count($vehicle->packages)) }} {!! link_to_route('packages.create_for_vehicle', 'Add', ['vehicle_id' => $vehicle->id], ['class' => 'btn btn-primary']) !!}</td>

Error #6

It looks like Laravel dropped support for SparkPost around 5.8 – so we are now getting these errors on all of our form submissions:

To fix this we need to install this package:
https://github.com/vemcogroup/laravel-sparkpost-driver

This package was giving us some issues when installing, in order to successfully install it we had to remove the 4.0 version that installed automatically with the package and instead install version 2.0 using the code below::

composer remove vemcogroup/laravel-sparkpost-driver


composer_memory_limit=-1 composer require vemcogroup/laravel-sparkpost-driver:^2.0

When we did this we ran into an issue that Guzzle 7.0 was not compatible with V2.0 of the SparkPost Package and could not install correctly as well, so to fix that we ran:

composer_memory_limit=-1 composer require guzzlehttp/guzzle:6.5.5

Once that package is installed its important to note that we also need to then run:

php artisan config:clear
php artisan cache:clear

The above gets the site working on our local machine, however when we deploy to the staging site we are still running into a different error screen which we will fix under Error #8 below, but first a general note.

General Error – Error #7

If you are getting the php memory limit error when running composer install or update, which looks like this:

To work around this issue run the code below, which tells PHP to keep trying instead of stopping after reaching the initial memory limit set on the server

composer_memory_limit=-1 composer install

Error #8:

On the staging server we are getting the error that allow_url_fopen must be enabled in php.ini. We login to cpanel and set this to enabled, but we still receive this message. So we will manually run the command below instead, which allows url_fopen for this 1 single command:

which composer

//for us this spits out /opt/cpanel/composer/bin/composer so we will then run

php -d allow_url_fopen=on /opt/cpanel/composer/bin/composer install

Error 9:

With the SparkPost API now working, we are getting the error below:

Client error: `POST https://api.sparkpost.com/api/v1/transmissions` resulted in a `400 Bad Request` response:
{\"errors\":[{\"message\":\"Unconfigured Sending Domain <example.com>

To fix this error we will open up config/mail.php and change the backup email address from hello@example.com to the actual address we want to use:

'address' => env('MAIL_FROM_ADDRESS', 'ActualEmailAddress'),
Categories
Laravel Samuel

Upgrading Laravel from 5.5 -> 5.6

Notes on Upgrading Laravel from 5.5 -> 5.6

Start by creating a new upgrade branch from the master branch:

git checkout –b laravel-5.5-upgrade –master

Next Purchase a Laravel shift using this new upgrade branch name

Merge the branch that is created by Laravel shift into this new upgrade branch

Git fetch origin
Git checkout shift-42238
Git checkout laravel-5.5-upgrade
Git merge shift-42238

Now its time to check how the site is doing on our local machine, but first we will want to update composer & clear config, route & view caches:

composer update
php artisan cache:clear
php artisan route: clear
php artisan view:clear

Now it’s time to fix any errors that cop up, our first error is:

array_keys() expects parameter 1 to be array, integer given

Solution: in app -> Http -> Middleware -> TrustProxies.php set the following:

protected $headers = [
    Request::HEADER_FORWARDED => 'FORWARDED',
    Request::HEADER_X_FORWARDED_FOR => 'X_FORWARDED_FOR',
    Request::HEADER_X_FORWARDED_HOST => 'X_FORWARDED_HOST',
    Request::HEADER_X_FORWARDED_PORT => 'X_FORWARDED_PORT',
    Request::HEADER_X_FORWARDED_PROTO => 'X_FORWARDED_PROTO',
];

our second error is: Class user not found. To fix this we update config -> auth.php to the following:

'model' => App\Models\User::class,
Categories
Laravel Samuel Uncategorized

Setting Composer To Use PHP 7.3 From Command Line

So we ran into a little bit of an issue today when upgrading Laravel from 5.6 -> 6.0. We updated the version of PHP using the MultiPHP Manager section in Cpanel, however when we then SSH’d into the server to pull in the updated Laravel code and run composer install we ran into the issue of composer using the system version of PHP. The full process we went through is below:

Update the version of PHP on MultiPHP manager page:

We then SSH’d into the server to pull in the new Laravel code. When we did this, we got the following error message:
To get around this issue we created a shim script, so now instead of running:
composer install

We instead ran:

~/bin/composer install

Composer now uses the version of PHP defined in the shim script, which in our case is PHP 7.3 and we are back to all green happy lines πŸ™‚

Categories
Fixing Stuff Laravel Samuel

Laravel Comapact PHP 7.3 Temporary Fix

With PHP 7.3 being automatically pushed out to a lot of servers recently we noticed a bug that came up on severeal older Laravel sites. The bug is:

compact(): Undefined variable: operator 

public function addWhereExistsQuery(self $query, $boolean = 'and', $not = false)
    {
        $type = $not ? 'NotExists' : 'Exists';
 
        $this->wheres[] = compact('type', 'operator', 'query', 'boolean');
 
        $this->addBinding($query->getBindings(), 'where');
 
        return $this;
    }

A Fix for this bug can be found on this stack overflow article: https://stackoverflow.com/questions/56726263/compact-undefined-variable-operator

The specific fix is:

$this->wheres[] = compact('type', 'operator', 'query', 'boolean');

you just remove the 'operator' parameter

Please note this is just a temporary fix to remove the error page. The long term fix for this is that the version of Laravel will need to be updated, and then composer update needs to be run to pull in the latest packages that will work with the new version of Laravel, and they will handle the new behavior of the compact method. The old version allowed for empty variables to be passed to the compact method, but in PHP 7.3 if an empty variable is passed to the compact method it presents you with that nice error message πŸ™‚