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
Samuel Traveling

Family Vacation

We just left our family vacation. The whole family (including Steve, Mal and all the kids + Ellen’s Parents and Sister came). This was the first time everyone took a trip together and the trip as a whole turned out to be so much fun. We went to Marco Island and stayed near some of Ellen’s parents friends. We basically just relaxed at the beach every day, and unlike most vacations where I’m ready to be back home by the last couple days I really felt like I could have stayed a lot longer. I didn’t take many pictures from the trip but I did snap one picture deep sea fishing:

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

Categories
Finance Samuel

Thanking Triple M

This post is about saying thanks to Pete. I wanted to float the idea of doing something on a recurring basis to thank Pete for creating his website. I love the concept that “we are the sum of the 5 people we spend the most time around”. By writing his blog Pete has allowed us to be around him virtually and soak up so many amazing, life altering principals. For that I’m extremely grateful to Pete. Trying to think of the best way to say thanks I’m reminded of another great quote “give me a big enough lever and I can move the world”. With that in mind it seems like the best gift we could give Pete is the power to amplify the leverage of his website. I’d love if other people would weigh in with hopefully bigger and better ideas but my brainstorm on this has surfaced the following idea:

The best way to increase the visibility and usefulness of the MMM site is to improve the forum. The forum scales, whereas Pete is one human, the forum is a collective of people and ideas, capable of generating amazing content at scale. If the forum was able to automatically bubble up the best content, and display it to users this would maximize the usefulness of the MMM site. Due to the nature of the current forum with repeat posts and hard to navigate threads we end up with a never ending train of advice for each subject which is not as beneficial as the best advice bubbled up to the surface by a voting algorithm (think stack overflow but for the FI world). If we could take all the content currently on the forum and put it inside of a stack overflow type system where the best answers are eventually bubbled to the top via user ratings, then the forum would potentially benefit countless more people, and Pete’s secrete mission would be 1 step closer to fruition https://www.mrmoneymustache.com/2013/02/16/weekend-edition-why-are-you-writing-this-blog-anyway/