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

clean seeding laravel DB

in the .env file set clean seed to true:

IS_CLEAN_SEED=true

then migrate with seed:

php artisan migrate:refresh --seed

The clean seeds are defined in the DatabaseSeeder class. The MVC repo has examples.

Categories
mySQL

mySQL Lesson 2

select *
from orders
order by id
limit 100;

select *
from order_items
order by id
limit 100;

Categories
mySQL

mySQL lesson 1

select a table in the db and show info from this table:

SELECT * FROM celebs;

create DB table:

CREATE TABLE celebs (id INTEGER, name TEXT, age INTEGER);

insert info into DB:

INSERT INTO celebs (id, name, age) VALUES (1, 'Justin Bieber', 21);

INSERT INTO celebs (id, name, age) VALUES (2, 'Beyonce Knowles', 33);

INSERT INTO celebs (id, name, age) VALUES (3, 'Jeremy Lin', 26);

INSERT INTO celebs (id, name, age) VALUES (4, 'Taylor Swift', 26);

update a row in the DB

UPDATE celebs
SET age = 22
WHERE id = 1;

SELECT * FROM celebs;

Add a new column to the table

ALTER TABLE celebs ADD COLUMN twitter_handle TEXT;

SELECT * FROM celebs;

add information to this new column

UPDATE celebs
SET twitter_handle = '@taylorswift13'
WHERE id = 4;

SELECT * FROM celebs;

delete rows that have a NULL value

UPDATE celebs
SET twitter_handle = '@taylorswift13'
WHERE id = 4;
DELETE FROM celebs WHERE twitter_handle IS NULL;

SELECT * FROM celebs;

Categories
php unit

Unit 8 Functions Part II

1.) Functions refresher

print the number of characters in your name:

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

2.) Functions Syntax

typical structure of a function:

function name(parameters) {
statement;
}


function helloWorld() {
echo "Hello world!";
}


3.) First Function


function displayName() {
echo "Samuel";
}
displayName();

5.) Returning Values

Instead of printing something to the screen, what if you want to make it the value that the function outputs so it can be used elsewhere in your program? In PHP, the return keyword does just that. It returns to us a value that we can work with. The difference between this and echo or print is that it doesn’t actually display the value.


function returnName() {
return "samuel";
}

6.) Parameters and Arguments

Functions wouldn’t be nearly as useful if they weren’t able to take in some input. This is where parameters or arguments come in. These are the variables or inputs that a function uses to perform calculations.

$name = "Samuel";
function greetings($name) {
echo "Greetings," .$name. "!";
}

greetings($name);

7.) Practice Defining multiple parameters


$name = "Samuel";
$age = "28";

function aboutMe($name, $age){
echo "Hello! My name is " .$name. " and I am " .$age. " years old";

}

aboutMe($name, $age);