Lavarel 快速學習自我挑戰 Day12


Sessions - Sessions 設定官方文件

Setting and Reading Sessions

  1. 加到 HomeController
1
2
3
4
$request->session()->put(['edwin'=>'master instructor']);
// session(['peter'=>'student']); //最常用

$request->session()->get('edwin');

Global Session Function Deleting

  1. 新增 session
1
2
3
session(['edwin2'=>'your teacher']);

return session('edwin2');
  1. 刪除 session:$request->session()->forget('edwin2');
  2. 刪除所有 session:$request->session()->flush();
  3. 顯示 session 狀態:return $request->session()->all();

Flashing Data

  1. 建立 flash data (只顯示一次的資料)
1
2
3
$request->session()->flash('message', 'Post has been created');

return $request->session()->get('message');
  1. data 保存久一點
1
2
3
$request->session()->reflash();

$request->session()->keep('message');

Sending Email / API - Mail 設定官方文件

mailgun

Mailgun 官方網站

mailgun 設定

  1. 設定 config/mail.php 的寄件人名稱與 mail
    'from' => ['address' => 'admin@pcelab.info', 'name' => 'Vincent Adler'],
  2. 設定 .env
1
2
3
MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=XXXXX
MAILGUN_SECRET=XXXXX
  1. 新增 mail 的 view (resources/views/mails/test.blade.php)
  2. 新增 routes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Route::get('/', function () {

$data = [

'title'=> 'Hi student I hope you like the course',
'content'=> 'This laravel course was created with a lot of love and dedication for you'

];

Mail::send('emails.test', $data, function($message){

$message->to('dtvgood202@gmail.com', 'Vincent')->subject('Hello student how are you');

});

});
  1. 新增套件:composer require guzzlehttp/guzzle
  2. SSL certification error - 修改 vendor/guzzlehttp/guzzle/src/Client.php:configureDefaults function 的 verify 改為 false

Git and Github (Version Control)

  1. 新增 branch 分支 git checkout -b newBranch
  2. 合併到主分支 git merge newBranch
  3. 刪除已合併到 master 的分支 git branch -d newBranch
Share