[PHP] [BiuldYourFirstApp] to build your first application: Conclusion-php Tutorial

Source: Internet
Author: User
Tags cloudflare dmca
[PHP] [BiuldYourFirstApp] to build your first application: This article is intended for beginners who have a certain understanding 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. modify the view file index. blade. php so that a prompt is displayed on the page when no notification is created.

@extends('app') @section('content')    YourNotices     
                     This Content:            AccessibleHere:            Is InfringingUponMyWorkHere:            NoticeSent:            ContentRemoved:                 @foreach ($noticesas $notice)                            {{ $notice->infringing_title }}                {!! link_to($notice->infringing_link) !!}                {!! link_to($notice->original_link) !!}                {{ $notice->created_at->diffForHumans() }}                                    {!! Form::open() !!}                    
  
                           {!! Form::checkbox('content_removed',$notice->content_removed,$notice->content_removed) !!}                    
   

{!! Form::close() !!} @endforeach ($noticesas $notice) @unless(count($notices))

Youhaven't sentanyDMCAnoticesyet!

@endunless@endsection

2. add the feedback after the new notification is sent. Here, the author uses a new package laracasts/flash and uses the command composer require laracasts/flash for installation.

Register 'laracasts \ Flash \ FlashServiceProvider 'in config/app. php ';

Then, write the corresponding code implementation prompt information in the controller.

 Middleware ('auth'); // register a middleware to verify all methods. parent ::__ construct ();} public function index () {$ notices = $ this-> user-> notices ()-> latest ()-> get (); // sort notices return view ('Notices. index', compact ('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');} pubilcfun Ction confirm (PrepareNoticeRequest $ request) {$ template = $ this-> compileDmcaTemplate ($ data = $ request-> all (); session ()-> flash ('dmp ', $ data); return view ('Notices. comfirm', compact ('Template'); // return a new view page and check the filled form data} public function store () {$ this-> creaeNotice ($ request); Mail: queue (['text' => 'emails. dmca '], compact ('notice'), function ($ message) use ($ notice) {$ message-> from ($ notice-> getOwnerEmai L ()-> to ($ notice-> getRecipientEmail ()-> subject ('dmca notic');}) flash ('your DMCA Notice has been delivered! '); 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 ;}}

Finally, add the feedback display area in app. blade. php on the main interface.

   
    
     
      
     DMCAApp   
     
      
@ Include ('FLASH: message') @ include ('partial. nav) // load the navigation bar @ yield ('content') // insert content
      
        Script
       
         Script 
       
      
     
    
   
  
 

3. add the submit button to the checkbox in the Content Removed column of the notices table and write the update method to write changes to the database.

 Middleware ('auth'); // register a middleware to verify all methods. parent ::__ construct ();} public function index () {$ notices = $ this-> user-> notices ()-> latest ()-> get (); // sort notices return view ('Notices. index', compact ('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');} pubilcfun Ction confirm (PrepareNoticeRequest $ request) {$ template = $ this-> compileDmcaTemplate ($ data = $ request-> all (); session ()-> flash ('dmp ', $ data); return view ('Notices. comfirm', compact ('Template'); // return a new view page and check the filled form data} public function store () {$ this-> creaeNotice ($ request); Mail: queue (['text' => 'emails. dmca '], compact ('notice'), function ($ message) use ($ notice) {$ message-> from ($ notice-> getOwnerEmai L ()-> to ($ notice-> getRecipientEmail ()-> subject ('dmca notic');}) flash ('your DMCA Notice has been delivered! '); Return redirect ('notices');} public function update ($ noticeId,) {$ isRemoved = $ request-> has ('content _ removed'); Notice :: findOrFail ($ noticeId)-> update (['content _ removed' => $ isRemoved]); return redirect ()-> back ();} 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 ;}}

Then the author removes the submit key.

4. use javascript to implement the above functions. the code is briefly displayed here.

Add custom javascript code for app. blade. php

   
    
     
      
     DMCAApp   
     
      
@ Include ('FLASH: message') @ include ('partial. nav) // load the navigation bar @ yield ('content') // insert content
      
        Script
       
         Script
        
          Script 
        
       
      
     
    
   
  
 

Modify index. blade. php to add asynchronous communication and prompt information. remove the submit button.

@extends('app') @section('content')    YourNotices     
                     This Content:            AccessibleHere:            Is InfringingUponMyWorkHere:            NoticeSent:            ContentRemoved:                 @foreach ($noticesas $notice)                            {{ $notice->infringing_title }}                {!! link_to($notice->infringing_link) !!}                {!! link_to($notice->original_link) !!}                {{ $notice->created_at->diffForHumans() }}                                    {!! Form::open(['data-remote','method' => 'PATCH','url' => 'notices/'.$notice->id]) !!}                    
  
                           {!! Form::checkbox('content_removed',$notice->content_removed,$notice->content_removed,['data-click-submits-form']) !!}                    
   

{!! Form::close() !!} @endforeach ($noticesas $notice) @unless(count($notices))

Youhaven't sentanyDMCAnoticesyet!

@endunless@endsection

Summary

The laravel framework shows the excellent easy-to-read features. This article only provides a brief introduction to the level limit. please continue to learn the relevant documents and videos.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.