Categories
Laravel Samuel

Animating Content Using AOS

We went on the hunt for a lightweight package to animate content into a Laravel project today. We found what looks to be a great package that we are trying out now, will report back findings and notes after using:

AOS Github Page:
http://michalsnik.github.io/aos/

There is a great ReadMe file located here:
https://github.com/michalsnik/aos/blob/next/README.md

Categories
Laravel Samuel

Upgrading Laravel from 5.1 -> 5.5 Part Two

In our second post of this upgrade series we are going to take our newly upgraded application from our local environment and push the new code up to the production server. For a detailed notes on actually upgrading your code base from 5.1 -> 5.5 go here: Upgrading Laravel from 5.1 -> 5.5

Steps We will Take:

– put site in maintenance mode: php artisan down

– run our deploy script
– delete vendor directory and run “composer install” with new code base

– upgrade version of php on the server to 7.1
– put site back up live: php artisan up

Troubleshooting Tips:

Undefined class constant ‘XLXS’
To Fix Run: composer update

Maatwebsite/excel 3.0.1 requires phpoffice/phpspreadsheet ^1.2
Phpoffice/phpspreadsheet 1.3.1 requires ext-iconv * -> the requested PHP extension iconv is missing

Fix for this is: yum install ea-php71-php-iconv

Maatwebsite/excel 3.0.1 requires phpoffice/phpspreadsheet ^1.2
Phpoffice/phpspreadsheet 1.3.1 requires ext-zip * -> the requested PHP extension zip is missing

Fix for this is: yum install ea-php71-php-zip

The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.
Fix for this: php artisan key:generate

Call to undefined method Illuminate\View\Factory::getFirstLoop()
Fix For this: php artisan view:clear

Categories
Laravel

Using Laravel Shift For The First Time

This is a list of useful steps to follow when upgrading Laravel using shift:

General Helpful Notes:

– Our first priority is to get Laravel onto the new version, and then work out the errors from there. If a package or dependency is erroring out take note of the package, then delete it from composer.json. Once the new version of Laravel fully installs, then add the packages one at a time by typing:

composer require package-name

If you get an error when running the above telling you that a higher version of the package is needed, then type:

composer require ^version# package-name

– Alt + Enter in PHPStorm will add a missing class to your file automatically. Super useful!

– At time we might need to copy an entire file from the new version of Laravel into our project. When we do this a handy tip is that PHPstorm will highlight on the left hand side any sections where the file has changed. You can go to this individual line ant hit Control + Alt + Z and that single line will revert to the previous copy allowing you to see the differences.

Step By Step Notes:

1.) Create a new release branch from master, name the branch something like “upgrade”.

2.) Purchase the shift you want, and have it performed on the upgrade branch.

3.) Review all pull request comments for additional changes, install Larave (deleting dependencies/packages as needed and keeping them in a list to add back later). Run “composer update” (if the pre-scripts fail, add –no-scripts)

4.) Now we are ready to fire up our application and check for any errors. Starting in Laravel 5.2 artisan serve is deprecated and you need to instead use:
php -S localhost:8080 -t public/

Testing & Error Code Notes:

1.) If you see the error message:
Access level to Illuminate\Routing\Router::substituteImplicitBindings() must be public (as in class Illuminate\Contracts\Routing\Registrar) in C:\wamp64\www\vendor\laravel\framework\src\Illuminate\Routing\Router.php on line 21

The fix for this is to find where this is being called and set it to public. To find in PHPStorm open up find in path (Control + Shift + F). Select whole project and then search for substituteBindings. In our case this is pulling up in our router.php file. Sure enough substitute bindings was set to protected, we change it to public and our error is resolved.

2.) If you see the error message:
Uncaught ReflectionException: Class log does not exist in

The fix for this is to open up your .env file and make sure that all of your values are enclosed in quotes. So for example starting from the top your values should look like: APP_ENV="local"

3.) If you see the error:
Class 'Illuminate\Html\HtmlServiceProvider' not found

The fix for this is:

Add this to your composer.json file:
"require": {
"laravelcollective/html": "5.1.*"
}

Run composer update

Add the following to your providers array in config/app.php

'providers' => [
Collective\Html\HtmlServiceProvider::class,
],

Add the aliases to the aliases array of config/app.php
'aliases' => [
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
],

Run composer dump-autoload -o
Run composer update

**make sure to run composer update before adding the service provider or else you will get the error:
Class 'Collective\Html\HtmlServiceProvider::class' not found

4.) If you see the error:

FatalErrorException in Paginator.php line 15:
Declaration of Illuminate\Pagination\Paginator::render(?Illuminate\Contracts\Pagination\Presenter $presenter = NULL) must be compatible with Illuminate\Contracts\Pagination\Paginator::render($view = NULL)

The fix for this we need to delete the current vendor folder then run composer install

Categories
Laravel Samuel

Setting up SparkPost On Laravel 5.6 Project

These are just shorthand notes from setting up SparkPost on a Laravel 5.6 project:

1.) Open up gitbash at the project root and run:

composer require guzzlehttp/guzzle

**If you get the error code below:

file could not be downloaded: allow_url_fopen must be enabled in php.ini (http:// wrapper is disabled in the server configuration by allow_url_fopen=0

**Then SSH into the server and run the command below to fix that:

php -d allow_url_fopen=1 /opt/cpanel/composer/bin/composer update

2.) Open config/mail.php and make sure the driver line is set to

'driver' => env('MAIL_DRIVER', 'log'),

3.) Verify that the following code is in config/services.php

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

4.) Add the following two lines to your .env file and upload:

MAIL_DRIVER=sparkpost
SPARKPOST_SECRET=secret-key-goes-here

Troubleshooting:

After completing the steps above are you getting the error message:
"Connection could not be established with host smtp.mailtrap.io [Connection refused #111]"

Then these steps will fix that error message:

1.) After uploading the new .env file clear the cache by running:

php artisan config:clear and php artisan cache:clear

2.) Get rid of any default mail settings in your .ENV file

Categories
Laravel Samuel

Notes on installing Laravel Site

Installing the site:

Deployment Script: Create a folder called “deploy” above the public_html directory. Update the URL paths inside our deploy script to use the URL paths of your local machine then chmod +x the script after uploading it.

Deploy Keys:

To allow the server to connect to the bitbucket repo we need to get our servers public key and add it to bitbucket, to do this we can run (cd ~/.ssh). Then run (cat id_rsa.pub) and copy the pub key file (control + insert + c to copy from terminal). If no public key file is present run (ssh-keygen) then copy the file. Next we will copy the key into Bitbucket, maximize the SSH terminal window if getting invalid key warning from bitbucket, spacing effects this. Next step is login to bitbucket, hit the settings page, then hit access keys > add key > past key into this window and save.

Manually Clone:

Navigate to one level above the public_html folder and create a new folder called (git). Inside this folder run: git clone repo-name (pull repo from bitbucket SSH repo clone)

*Please note, check to see if the repo name matches the project name inside the deploy script. These must match for the deploy script to work.

Run Composer:

If composer has been installed on the server already, you can navigate to the project root and run: (composer install). This will pull in all of the project dependencies and store them in the vendor folder.

Create Database:

Create an empty database and then add the credentials into the .enf file located in the projects root

Update .ENV File:

The ENV file is not version controlled and is unique to each host its on. This file has defaults for the URL, Database Connection, Spark Post Email Connection, & Google Maps Key.

Create Backup Scripts + CronJobs

  • backups -> daily/weekly/monthly folders
  • backupscripts -> daily/weekly/monthly scripts
  • cpanel -> crong jobs -> daily/weekly/monthly timing with the command pointed at each separate script

Commands to run once all files are present:

1.) Navigate to the deploy script and run it (./deploy-script). The first time this script runs it will create backup folders on the server along with a db connection file.

2.) After the deploy script runs, from the project root you will want to manually run: (php artisan migrate & php artisan db:seed). This will add all the database tables and default user information to the site.

Create Symlink:

The actual Laravel files live above the public_html folder for added security. For this to work we will need to create a symlink from public_html to the public Laravl Folder.

***Please note: If you are planning to have the site use a Let’s Encrypt SSL you will need to copy the .well-known folder into the Laravel Public folder. Before doing this you must add the following lines to the gitignore file:

/public/.well-known
/public/.htaccess

To Create the symlink run:

ln -s /home/user/git/repo-name/public /home/user/public_html

or if you want to go with the shorthand you can use:

ln -s ~/git/repo-name/public ~/public_html

*Please note you will need to change the file paths above to match your actual file paths

Categories
Fixing Stuff Laravel Samuel

FIxing Laravel Query

We had a query that was breaking several pages after a client removed information that was referenced from another table (even thought the system explicitly warns them from removing this info lol). To fix the errors messages the client was receiving we needed to update our controller so that our database lookup only included items with vehicles present. To do this we made the following changes in two files:

Changes to our Inquiries Controller:
Step 1:
Replacing our DB lookup:
Old Query: $inquiries = Inquiry::all();

New Query: $inquiries = Inquiry::whereHas('vehicle_id')->get();

Step 2:
Fixing error message: Illuminate\Database\Eloquent\Builder::whereHas() must be an instance of Closure, none given'

Instead of using whereHas we were able to fix the error message by simply using has. This was a simple error in hindsight, we don’t need to query to lookup multiple items, we only need to know if the inquiry HAS a vehicle associated with it.

Our Final working fix: $inquiries = Inquiry::has('package.vehicle')->get();

Changes to our separate view files:
We also had issues related to inquiries on 4 other pages. The system references inquiries on part types as well and these pages all referenced an individual view file, so instead of refactoring this code into a controller we took the path of least resistance and made the changes below:

Original code:
@foreach($inquiries as $inquiry)
package; ?>
vehicle; ?>

{!! link_to_route('inquiries.show', $inquiry->id, ['id' => $inquiry->id]) !!} {!! link_to_route('vehicles.show', $vehicle->display(), ['id' => $vehicle->id]) !!} {!! link_to_route('packages.show', $package->display(), ['id' => $package->id]) !!} {{ $inquiry->getType()->name }} {{ $inquiry->getEngine()->name }} {{ $inquiry->getDriveTrain()->short_name }} {{ $inquiry->getMarking()->name }} {!! Helper::sortDollarAmount($inquiry->getPrice()) !!} {{ $inquiry->name }} {{ $inquiry->agency }} {{ $inquiry->email }} {{ $inquiry->displayPhone() }} {!! link_to_route('inquiries.excel', 'Excel', ['id' => $inquiry->id], ['class' => 'success']) !!}
 / {!! Form::deleteModelLink('Inquiry', $inquiry->id, 'inquiries') !!}

@endforeach

Changed Code:
@foreach($inquiries as $inquiry)
package; ?>
vehicle; ?>

@if($vehicle)

{!! link_to_route('inquiries.show', $inquiry->id, ['id' => $inquiry->id]) !!} {!! link_to_route('vehicles.show', $vehicle->display(), ['id' => $vehicle->id]) !!} {!! link_to_route('packages.show', $package->display(), ['id' => $package->id]) !!} {{ $inquiry->getType()->name }} {{ $inquiry->getEngine()->name }} {{ $inquiry->getDriveTrain()->short_name }} {{ $inquiry->getMarking()->name }} {!! Helper::sortDollarAmount($inquiry->getPrice()) !!} {{ $inquiry->name }} {{ $inquiry->agency }} {{ $inquiry->email }} {{ $inquiry->displayPhone() }} {!! link_to_route('inquiries.excel', 'Excel', ['id' => $inquiry->id], ['class' => 'success']) !!}
 / {!! Form::deleteModelLink('Inquiry', $inquiry->id, 'inquiries') !!}

@endif
@endforeach