問題所在: routes.php 的 middleware : web
這裡有解釋說web已經預設當做是middleware了 但是你在routes.php 又做了一次
此時可以 輸入
$ php artisan routes
此時會發現所有Middleware都有兩個web 這就是問題,此時只要將Middleware的web移除掉即可,Session data就會正常運作了!!!
$ php artisan routes
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=<<your email address>>
MAIL_PASSWORD=<<app password>>
MAIL_ENCRYPTION=tls
有用ssl就用以下設定MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=<<your email address>>
MAIL_PASSWORD=<<app password>>
MAIL_ENCRYPTION=ssl
Route::get('sendemail', function () {
$data = array(
'name' => "Learning Laravel",
);
Mail::send('emails.welcome', $data, function ($message) {
$message->from('yourEmail@domain.com', 'Learning Laravel');
$message->to('yourEmail@domain.com')->subject('Learning Laravel test email');
});
return "Your email has been sent successfully";
});
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
</head>
<body>
<h2>Learning Laravel!</h2>
<div>
Welcome to {!! $name !!} website!
</div>
</body>
</html>
var
let
var a = 1;
var b = 2;
if (a === 1) {
var a = 11; // the scope is global
let b = 22; // the scope is inside the if-block
console.log(a); // 11
console.log(b); // 22
}
console.log(a); // 11
console.log(b); // 2
另一個範例,可以看出var作用域變數內都會是同一個,而 let 只作用該scope 所以裡面的不一樣function varTest() {
var x = 1;
if (true) {
var x = 2; // same variable!
console.log(x); // 2
}
console.log(x); // 2
}
function letTest() {
let x = 1;
if (true) {
let x = 2; // different variable
console.log(x); // 2
}
console.log(x); // 1
}
!!!有些 let 需要注意的事情if (x) {
let foo;
let foo; // SyntaxError thrown.
}
下面也是相同狀況switch (x) {
case 0:
let foo;
break;
case 1:
let foo; // SyntaxError for redeclaration.
break;
}
var x = 'global'; let y = 'global'; console.log(this.x); //"global"
console.log(this.y); //undefined
var list = document.getElementById("list");
for (let i = 1; i <= 5; i++) {
let item = document.createElement("li");
item.appendChild(document.createTextNode("Item " + i));
item.onclick = function (ev) {
console.log("Item " + i + " is clicked.");
};
list.appendChild(item);
}
如果用var是不行的,結果會是 var 都是 6x = 42;
var y = 43;
myobj = new Number();
myobj.h = 4; // create property h
delete x; // returns true (can delete if declared implicitly)
delete y; // returns false (cannot delete if declared with var)
delete Math.PI; // returns false (cannot delete predefined properties)
delete myobj.h; // returns true (can delete user-defined properties)
delete myobj; // returns true (can delete if declared implicitly)
/**
* Example 1
*/
console.log(x === undefined); // true
var x = 3;
/**
* Example 2
*/
// will return a value of undefined
var myvar = "my value";
(function() {
console.log(myvar); // undefined
var myvar = "local value";
})();
則他在執行時會這樣做:/**
* Example 1
*/
var x;
console.log(x === undefined); // true
x = 3;
/**
* Example 2
*/
var myvar = "my value";
(function() {
var myvar;
console.log(myvar); // undefined
myvar = "local value";
})();
而 let 則是沒有這個特性 所以他會直接是錯的console.log(x); // ReferenceError
let x = 3;
另外function 宣告也有這個特性 (function 附值則沒有)/* Function declaration */
foo(); // "bar"
function foo() {
console.log("bar");
}
/* Function expression */
baz(); // ReferenceError: baz is not a function(it's undefined!!!)
var baz = function() {
console.log("bar2");
};
function 若是沒有return值 typeof 會是undefined 若有 typeof 則看return 是什麼型態。var TestVar;
alert(TestVar); //shows undefined
alert(typeof TestVar); //shows undefined
if (typeof a === "undefined")
// or
if (a === undefined)
// or
if (a == undefined) // but see note below
null == undefined // true
2. nullvar TestVar = null;
alert(TestVar); //shows null
alert(typeof TestVar); //shows object
如何判斷是不是null呢 ?if (a === null)
// or
if (a == null) // but see note below
第二種判斷方式 當 a 是 undefined也也會是true ,因為null == undefined // true
3. ===
and !==
strict comparison operators"1" == 1
is true , "1" === 1
is falseif (!a) {
// `a` is falsey, which includes `undefined` and `null`
// (and `""`, and `0`, and `NaN`, and [of course] `false`)
}
因為DOM操作時(getElementById(), nextSibling(), childNodes[n], parentNode()),如果找不到Node就會回傳null (也就是說有定義,但用null表示沒有此Node)所以不需要特別做null與undefuned之間的差別判斷