[PHP][Biuld Your First App ]搭建你的第一個應用: Mandrill 篇

來源:互聯網
上載者:User
本文適用於對 PHP 和 laravel 架構有一定瞭解並已經看完laravel入門視頻:Laravel 5 Fundamentals 的初學者。本文內容主要講解如何搭建一個有簡單註冊、登入、填寫表單、產生文本、預覽、發送郵件和展示的 web 應用。

視頻作者的視頻經常被非法上傳的 youtube 上,想要向有關當局反映必需填寫一個 DMCA 檔案並附上源視頻地址和非法上傳的視頻地址,還要表達一些訴求。為了方便起見,網站被設計成填寫表單自動產生 DMCA 檔案自動發送郵件。

如果還沒看請先下載觀看:

  • 連結: http://pan.baidu.com/s/1sjXeLQH
  • 提取密碼:jjb5

1.簡化在文中多次出現的 Auth::user() 直接在父類中聲明。

父類

user = $this->signedIn = Auth::user();    } } 

子類

middleware('auth');//註冊一個中介軟體對所有方法進行驗證    parent::__construct();//繼承父類的建構函式並添加新的內容  }   public function index()  {    return $this->user->notices;  }   public function create()  {    // get list of providers    $provider = Provider::list('name','id');     // load a view to create a new notice    return view('notices.create',compact('providers'));  }   pubilcfunction confirm(PrepareNoticeRequest $request)  {      $template = $this->compileDmcaTemplate($data = $request->all());       session()->flash('dmca',$data);       return view('notices.comfirm',compact('template'));//返回一個新視圖頁,檢查填寫的表單資料  }   public function store()  {      $this->creaeNotice($request);       return redirect('notices');  }   public function compileDmcaTemplate($data)  {      $data = $data + [          'name' => $this->user->name,          'email' => $this->user->email,      ];//為模版傳入資料,拼接資料       return view()->file(app_path('Http/Templates/dmca.blade.php'),$data);  }   private function createNotice(Request $request)  {      $notice = session()->get('dmca') + ['template' => $request->input('template')];       $notice = $this->user->notices()->save($notice);       return $notice;  } } 

2.在使用 ManDrill 之前首先安裝相應組件,使用命令 composer require guzzlehttp/guzzle:~4.0 。在環境配置中配置相應 MAIL_DRIVER=mandrill 。在 config/services.php 中配置 'mandrill => ['secret =>'註冊 mandrill 獲得 APIkey'] 。

發送 notice

成功

小結

本節使用 mandrill 引擎實現發送郵件功能。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.