[PHP] [BiuldYourFirstApp] build your first application: Mandrill this article applies to beginners who have some knowledge of PHP and laravel frameworks and have read the laravel getting started video: Laravel 5 Fundamentals. This article describes how to build a web application with simple registration, logon, form filling, text generation, preview, email sending, and display.
The video of the video author is often illegally uploaded to youtube. if you want to report to the relevant authorities, you must fill in a DMCA file with the source video address and the video address illegally uploaded, and express some demands. For convenience, the website is designed to enter a form to automatically generate DMCA files and send emails automatically.
If you haven't seen it yet, please download and watch it first:
- Link: http://pan.baidu.com/s/1sjXeLQH
- Password extraction: jjb5
1. simplify the Auth: user () that appears multiple times in the text and directly declare it in the parent class.
Parent class
user = $this->signedIn = Auth::user(); } }
Subclass
Middleware ('auth '); // register a middleware to verify all methods. parent ::__ construct (); // inherit the constructor of the parent class and add new content} 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'); // return a new view page and check the filled form data} public function store () {$ this-> creaeNotice ($ request); return redirect ('notices');} public function compileDmcaTemplate ($ data) {$ data = $ data + ['name' => $ this-> user-> name, 'Email '=> $ this-> user-> email,]; // input data for the template and splice the data 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. install the relevant components before using ManDrill, and run the command composer require guzzlehttp/guzzle :~ 4.0. Configure MAIL_DRIVER = mandrill in the environment configuration. In config/services. php, configure 'mandrill => ['secret => 'Register mandrill to get apikey'].
Send notice
Successful
Summary
This section uses the mandrill engine to send emails.