Categories
Fixing Stuff Laravel Samuel

Fixing Local Laravel Migration On Wamp 3.0.6

So We ran into an issue today when trying to migrate an old project on a newer version of wamp. The error we kept getting is:


[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default val
ue for 'created_at' (SQL: create table `marketing_sources` (`id` int unsign
ed not null auto_increment primary key, `name` varchar(100) not null, `note
s` text null, `created_at` timestamp default 0 not null, `updated_at` times
tamp default 0 not null) default character set utf8 collate utf8_unicode_ci
)

This error is caused by mysql not accepting a timestamp of 0 as the default set time. To fix this issue open up:

app > config > local-environment-folder > database.php

Then add the following line:
'strict' => true

*please note if you are using mysql then add this line to the mysql array.

Categories
Code Academy php unit Samuel

PHP Unit 11 advanced Arrays and Maps

lesson 1 Review of Arrays:


$fruits = array ('bananas', 'apples', 'pears');
echo $fruits[1]; /* Your code here! */

Lesson 2 Associative Arrays


// This is an array using integers as the indices...
$myArray = array(2012, 'blue', 5);

// ...and this is an associative array:
$myAssocArray = array('year' => 2012,
'colour' => 'blue',
'doors' => 5);

// This code will output "blue"...
echo $myArray[1];
echo '
';

// ... and this will also output "blue"!
echo $myAssocArray['colour'];

Lesson 3 Using Arrays as Maps


// This is an array using integers as the indices.
// Add 'BMW' as the last element in the array!
$car = array(2012, 'blue', 5, 'BMW');

// This is an associative array.
// Add the make => 'BMW' key/value pair!
$assocCar = array('year' => 2012,
'colour' => 'blue',
'doors' => 5,
'make' => 'BMW');

// This code should output "BMW"...
echo $car[3];
echo '
';

// ...and so should this!
echo $assocCar['make'];

**this lesson errors out when you try to submit it. Add a line after the ‘make’ line, something like ‘make’ => ‘BMW’);+ and hit submit. When it errors out then delete the + after the ; and hit submit again. Seems to be a bug with code academy validation.

Lesson 4 Accessing Associative Arrays


// This is an array using integers as the indices...
$myArray = array(2012, 'blue', 5, 'BMW');

// ...and this is an associative array:
$myAssocArray = array('year' => 2012,
'colour' => 'blue',
'doors' => 5,
'make' => 'BMW');

// This code will output "blue".
echo $myArray[1];
echo '
';

// Add your code here!
echo $myArray[1];
echo $myAssocArray['make'];

Lesson 5 Iterating Over Associative Arrays


$food = array('pizza', 'salad', 'burger');
$salad = array('lettuce' => 'with',
'tomato' => 'without',
'onions' => 'with');

// Looping through an array using "for".
// First, let's get the length of the array!
$length = count($food);

// Remember, arrays in PHP are zero-based:
for ($i = 0; $i < $length; $i++) { echo $food[$i] . '
';
}

echo '

I want my salad:
';

// Loop through an associative array using "foreach":
foreach ($salad as $ingredient=>$include) {
echo $include . ' ' . $ingredient . '
';
}

echo '

';

// Create your own array here and loop
// through it using foreach!

$hockeyTeams = array (
'blues' => 'great',
'hawks' => 'bad',
'wings' => 'worst');

//loop through array using "foreach"
foreach ($hockeyTeams as $team=>$include) {
echo $include . ' ' . $team . '
';

}

Lesson 6 Multidimensional Arrays

$deck = array(array('2 of Diamonds', 2),
array('5 of Diamonds', 5),
array('7 of Diamonds', 7),
array('8 of Hearts', 8));

// Imagine the first chosen card was the 7 of Diamonds.
// This is how we would show the user what they have:
echo 'You have the ' . $deck[2][0] . '!';

Lesson 7 putting it all togather


// On the line below, create your own associative array:
$myArray = array (
'cubs' => 'should hopefully be out soon');

// On the line below, output one of the values to the page:
echo $myArray['cubs'];

// On the line below, loop through the array and output
// *all* of the values to the page:

foreach ($myArray as $baseballTeam=>$list){
echo 'the' . ' ' . $baseballTeam . ' ' . $list;
}

Categories
Code Academy php unit Samuel

PHP Unit 10

Lesson 1:

// Create a Person class here:
class Person {

}

// And create a Person instance called $me here:
$me = new Person();

Lesson 2:

class Person {
public $isAlive = true;

function __construct($name) {
$this->name = $name;
}

public function dance() {
return "I'm dancing!";
}
}

$me = new Person("Shane");
if (is_a($me, "Person")) {
echo "I'm a person, ";
}
if (property_exists($me, "name")) {
echo "I have a name, ";
}
if (method_exists($me, "dance")) {
echo "and I know how to dance!";
}

Lesson 3:

class Shape {
public $hasSides = true;
}

class Square extends Shape {

}

$square = new Square();
// Add your code below!
if (property_exists($square, "hasSides")) {
echo "I have sides!";
}

lesson 4:

class Vehicle {
public function honk() {
return "HONK HONK!";
}
}
// Add your code below!

class Bicycle extends Vehicle {
public function honk() {
return "Beep beep!";
}
}

$bicycle = new Bicycle();
echo $bicycle->honk();

Lesson 5:

class Vehicle {
final public function honk() {
return "HONK HONK!";
}
}
// Add your code below!

class Bicycle extends Vehicle {
public function honk() {
return "Beep beep!";
}
}

$bicycle = new Bicycle();
echo $bicycle->honk();

Lesson 6:

class Person {

}
class Ninja extends Person {
// Add your code here...
const stealth = "MAXIMUM";

}
// ...and here!
echo Ninja::stealth;

lesson 7:

class King {
// Modify the code on line 10...
public static function proclaim() {
echo "A kingly proclamation!";
}
}
// ...and call the method below!
King::proclaim();

Lesson 8:

class Person {
public static function say() {
echo "Here are my thoughts!";
}
}

class Blogger extends Person {
const cats = 50;
static public $cats = "50";
}

Blogger::say();
echo Blogger::$cats;

Categories
Fixing Stuff Laravel Samuel

Laravel Local Environment Troubleshooting

Ran into this error today after setting up local environment:

The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.

Luckily there is a simple fix for this, documented below:

php artisan key:generate
*This will save an APP_KEY to your local .env file which will then be used to encrypt data.

Categories
php unit Samuel

Unit 9 Object Oriented Programming, Part 1

Unit 1 and 2 are review

// The code below creates the class
class Person {
// Creating some properties (variables tied to an object)
public $isAlive = true;
public $firstname;
public $lastname;
public $age;

// Assigning the values
public function __construct($firstname, $lastname, $age) {
$this->firstname = $firstname;
$this->lastname = $lastname;
$this->age = $age;
}

// Creating a method (function tied to an object)
public function greet() {
return "Hello, my name is " . $this->firstname . " " . $this->lastname . ". Nice to meet you! :-)";
}
}

// Creating a new person called "boring 12345", who is 12345 years old ;-)
$me = new Person('boring', '12345', 12345);

// Printing out, what the greet method returns
echo $me->greet();

Unit 3:

class Person{

}
$teacher = new Person();
$student = new Person();

Unit 4:


class Person{
public $isAlive = true;
public $firstname; //don't assign values to these in the public class, define them locally
public $lastname;
public $age;

}

$teacher = new Person();
$student = new Person();

//print out info
echo $teacher->isAlive; //note don't add a $to the isAlive value here it will cause syntax error

?>

unit 5:

class Person{
public $isAlive = true;
public $firstname; //don't assign values to these in the public class, define them locally
public $lastname;
public $age;

//assign values
public function __construct($firstname, $lastname, $age) {
$this->firstname = $firstname;
$this->lastname = $lastname;
$this->age = $age;

}

}

$teacher = new Person("boring", "12345", 12345);
$student = new Person("sam", "bell", 28);

//print out info
echo $teacher->isAlive;
echo $student->age;


unit 8:

class Dog {
public $numLegs = 4;
public $name;

public function __construct ($name){
$this->name = $name;

}

public function greet(){
return " Hello, my name is " . $this->name . ". nice to meet you";

}

public function bark(){
return "Woof!";
}

}

$dog1 = new Dog ("Barker");
$dog2 = new Dog ("Amigo");

echo $dog1->bark();
echo $dog2->greet();

?>

unit 9:


// Your code here
class Cat {

public $isAlive = true;
public $numLegs = 4;
public $name;
}

public function __construct ($name){
$this->name = $name;

}

public function meow(){
return "Meow meow";
}

$cat1 = new Cat ("CodeCat");

echo $cat1->meow();

}

Categories
Fixing Stuff Samuel

Bathroom Remodel Project Notes

We recently did a bathroom remodel on a rental unit and I wanted to keep notes for myself to remember what went well in the process and what materials we used.

Materials List:

screws

drywall

backer-board

img_20160923_175011471

img_20160923_175022553

*note this is not a full materials list, just some of the items I deemed important during the process.

Cost Estimates:

Framing: 900$. Add load bearing wall to shore up 2nd floor bathroom, sister new wood beams to old notched beams, run helper boards (2X4’s) in each floor joist so there is a new, much more level support to lay the sub-floor on. Frame in the entire new bathroom, lay the 1/2 inch plywood subfloor.

Plumbing: 1,400$. Cut out old cast iron main stack + cut out old shower line and old sink link. Main stack replacement with PVC, shower and sink replacement with pvc, new pex water lines run from basement up to first floor, copper stub outs for sink, toilet, and shower, toilet flange put in place 2 inches above the subfloor to leave space for backerboard and tiles.

Electrical: KNOB & TUBE WIRE Remove and replace the existing knob & tube wire with romex wire in the dining room that feeds the ceiling fixture, switch and an outlet in the interior walls. 2ND FLOOR Replace the knob & tube wire to the 3way switches and the light fixture for the 2nd floor step light.
Replace the knob & tube wire from the light switch to the ceiling fixture in the two bedrooms. Install ceiling fan rated boxes for the two bedrooms. 2ND FLOOR HALL BATH Supply and install one 110cfm combo exhaust fan/light controlled by a s/p switch and 30min timer. Install one vanity light fixture controlled by a s/p switch. Install one GFI outlet. Install new circuits from the electric panel for the new work. SMOKE DETECTOR Install one arc fault breaker. Install one combo smoke/carbon detector in the basement. Install one smoke detector on the 1st floor. Install two smoke detectors and one combo smoke/carbon detector
on the 2nd floor. Electrical & Lighting 2,485.00

Finish Work: Install drywall on dining room ceiling, tape sand and smooth, prime, texture, and paint. INstall custom book sshelf with a face frame for removable access to plumbing and electrical work. Prime and paint bookshelf. Install 3&1/4th inche crown molding in dining room. Caulk and fill nail holes, paint to math trim. Install 1/2 inch drywall on walls, tape all joints, sand and smooth. Patch linen closet and ceiling / custom texture ceiling. Prime and paint walls and ceiling, 2 coats. Install 1/2 cement board on floor for tile, install customer supplied tile on floor and shower walls. Grout tile and wipe clean. Replace window with premium Cambridge windows, install composite jambs and casings around window and caulk. Make and install custom door casings and 4&1/4 inch baseboards. Install vanity wall cleats and new melamine shelves in line closet. Total cost 6,325.00$

Photos: