Categories
php unit

Unit 7 Functions

This is just useful notes for my own later use. Spoiler alert if you don’t want the answers to these lessons than don’t read on any farther.

Lesson 7:

1.) Introducing Functions

strlen() string function. You pass this a string or a varialbe containing a string and it will return the number of characters in the string. Example:

$length = strlen("Samuel");
print $length;

2.) String Functions

substr() You pass this function the string you want to get a subsctring of, the character in your string to start at, and how many characters you want after your starting point. For example:

print the first 3 letters of my name:

$myname = "Samuel Bell";
$partial = substr($myname,0,3);
print $partial;

print my name in uppercase:

$uppercase = strtoupper($myname);
print $uppercase;

print my name in lowercase:

$lowercase = strtolower($uppercase);
print $lowercase;

Categories
Fixing Stuff Laravel Samuel

stop tracking changes to a file in Sourcetree

Came across an annoying issue the past couple times I tried pushing commits to the remote repo on a current project. My local machine has a “nesting” error when serving this project locally that that I wrote about fixing in a previous post. Well now the issue was when I went to commit some new code it wanted to commit the bootstrap auto loader file, which of course I did not want committed to the repo since this is only a problem on my local machine.

So step 1 opened the .gitignore file and added bootstrap/autoloader.php to it…… and nothing. Source tree still kept trying to force me to merge in the change to the file. I then tried “stop tracking this file” in source tree by right clicking on it and selecting the stop tracking option. Still nothing. So then tried restarting source tree, pulling down ect… all various things to try and get sourcetree to stop tracking the file to no avail. So finally went searching for a git command that would force sourcetree to ignore the file and came upon:

git update-index --assume-unchanged file.filename

To run this I simply opened up gitbash, which we covered installing on windows in a previous post. So open up gitbash, cd to boostrap, then run our handy new command: git update-index –assume-unchanged file.filename

Viola the next time I opened source tree the file was no longer hanging in the uncommitted changes :). If you were running into a similar issue hopefully this simple git command will help you out too!

—update—
If we need to stop tracking an entire directory use:

git rm -r --cached path_to_your_folder/

Categories
Fixing Stuff Laravel Samuel

laravel email error notes

troubleshooting a couple small laravel errors. First one = “belongs-to-many” database lookup error. It was from a view trying to show old data that was missing (IE we had a data set present, then half of it was deleted and the site did not gracefully degrade to still show the view). The fix for this was to just purge the rest of the data (it happened to be test data so that was fine). Now since a user can’t input incomplete data into the view the page should be good to go.

then we had a contact form timing out a “swiftmailer” error. We had the .env file on port 465 but needed 587, and then we noticed there were a couple things hard coded in config > mail.php that were from a previous project. We updated this mail file to the correct info, and also made the needed changes in the .env file so that in the future that file can quickly override the mail.php file for ease of updating.

BadMethodCallException] This cache store does not support tagging. Laravel file and database drivers doesn’t support tags.

to fix find the cache drive in .env file and update it to:
CACHE_DRIVER=array

Categories
Laravel Samuel

simple laravel form verification

This post is simply a note of an item I did today to fix a little issue on a select form in laravel:

The issue was form verification on a select drop down box, the default value was passing the verification test since it in fact has a “Value”, solution =


update the drop down to show default wording on the front end but leave a blank value in the form field:

{{ Form::select('sales_counselor', ['' => 'Select Counselor'] + $users,

add a check to make sure the sales counselor field has a value, a check that the default value above will not pass:
'sales_counselor' => 'required|exists:users,id',

Categories
Fixing Stuff Laravel Samuel

Fixing PHP Error: Maximum function nesting level of ‘100’ reached, aborting

when copying a Laravel project from production down to my local machine today I got the following error while trying to access a specific page:

PHP Error: Maximum function nesting level of '100' reached, aborting

This was a first for me to see this, also of note I was not running this locally on wamp, I was simply serving the file with php artisan serve on windows using git bash. To fix the issue we took the following steps:

-locate the controller that powers the page generating the error (if you don’t know this off the top of your head, start back at your routes.php file). Look through the routes file unitl you find the correct controller.

-open up the controller and locate the function that is controlling the front end view (the page where your error is occurring). Next test to make sure you have the right function by adding dump and die to the top of your function:

dd($value);
*note you can also just use something like: dd('test');

-if you have the correct spot then the page will display your DD (dump and die) message. Once you confirm this then add the code below to fix the maximum function nesting error:

ini_set('xdebug.max_nesting_level', 200); //put this in here to fix local ini_set limit

That’s all there is too it. Also a side note its not a great practice to do this as a long term fix, there are probably larger issues at play that need to be addressed. But in my current case this worked perfectly and if anyone out there is running into the same issue hopefully this helps you solve it.

Categories
Laravel Samuel

Installing Laravel Spark on a new Project

These are mainly just notes copied from laravel docs. Just wanted them in this specific order so when I came looking back at them I could follow them easier:

First, download the Laravel installer using Composer:

composer global require "laravel/installer"

Make sure to place the ~/.composer/vendor/bin directory (or the equivalent directory for your OS) in your PATH so the laravel executable can be located by your system.

Next install a fresh new laravel project:

laravel new project-name

Next, add the following repository to your composer.json file:


"repositories": [
{
"type": "composer",
"url": "https://spark-satis.laravel.com"
}
],

Note: don’t add this at the bottom of the file, put it right under the require-dev section.

You should also add the following dependencies to your composer.json file’s require section:


"laravel/spark": "~1.0",
"laravel/cashier": "~6.0"

Next run the composer update command. This will add all the dependencies and clone in spark. Also note you will have to add a github token, which is stored in: C:/Users/computer-user-name/AppData/Roaming/Composer/auth.json

**Note you need to link laravel spark with your github account, and join the repo before composer will have access to clone it into your project**

Next add 2 providers to the confing/app.php file:

Laravel\Spark\Providers\SparkServiceProvider::class,
Laravel\Cashier\CashierServiceProvider::class,

Next run the spark install command:
php artisan spark:install --force
**note you must add the 2 providers into the ‘providers’ => [ section on line 124

After spark has successfully installed add the following provider to the config/app.php file again in the providers section:

App\Providers\SparkServiceProvider::class,

Now we are ready to run the DB migrations. If you get the @homestead error just update the .env file to use your local db creds.