[PHP] [Biuld Your First app] Build your application: End

Source: Internet
Author: User
Tags compact dmca
This article is intended for beginners who have a certain understanding of the PHP and laravel framework and have read the Laravel introductory video: Laravel 5 Fundamentals. This article explains how to build a Web app that has simple registration, login, fill out forms, generate text, preview, send mail, and show.

Video author videos are often illegally uploaded on YouTube and want to reflect to the authorities the need to fill out a DMCA file with the source video address and an illegally uploaded video address, as well as to express some claims. For convenience, the website is designed to fill out the form automatically generated by the DMCA file automatically sent by mail.

If you haven't seen it, please download it first:

    • Links: Http://pan.baidu.com/s/1sjXeLQH
    • Extract Password: jjb5

1. Modify the view file index.blade.php so that the page can be prompted to tell the user when no notification is created.

@extends (' app ') @section (' content ')
 
  Yournotices     
  
   
    This Content:AccessibleHere:Is InfringingUponMyWorkHere:NoticeSent:Content                Removed: @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 feedback after sending a new note. Here the author uses a new package Laracasts/flash, which is installed using the command composer require Laracasts/flash.

First register ' Laracasts\flash\flashserviceprovider ' in config/app.php;

Then write the corresponding code in the controller to implement the prompt information.

 Middleware (' auth ');//Register a middleware to validate all methods parent::__construct ();  The Public Function index () {$notices = $this->user->notices ()->latest ()->get ();//descending order 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 ')); } pubilcfunction confirm (Preparenoticerequest $request) {$template = $this->compiledmcatemplate ($data = $reque       St->all ());       Session ()->flash (' DMCA ', $data); Return view (' Notices.comfirm ', compact (' template '));//Return a new view page to check the completed form data} public function Store () {$this->cre       Aenotice ($request); Mail::queue ([' Text ' = ' EMAILS.DMCA '],compact (' notice '), function ($message) use ($notice) {$message->from ($n Otice->getowneremail ())->to ($notice->getrecipientemail ())->subjeCT (' DMCA Notice ');       }) Flash (' Your DMCA notice has been delivered! ');  Return redirect (' notices ');          The Public Function compiledmcatemplate ($data) {$data = $data + [' name ' = = $this->user->name, ' Email ' + $this->user->email,];//for the template incoming data, splicing data return view ()->file (App_path (' Http/templates  /dmca.blade.php '), $data); } Private Function Createnotice (Request $request) {$notice = Session ()->get (' DMCA ') + [' template ' = + $reque       St->input (' template ')];       $notice = $this->user->notices ()->save ($notice);  return $notice;  } }

Finally, the feedback display area is added in the main interface app.blade.php.

 
    
  
     
   
      
    
       
     
      Dmcaapp   
     
      
       
        @include (' flash::message ')  @include (' Partial.nav)//load navigation bar   @yield (' content ')//content Insertion      
     
      
    
     
   
    
  
   
 
  

3. Add the Submit button for the checkbox in the Content removed column in the notices table, and write the Update method to write the changes to the database.

 Middleware (' auth ');//Register a middleware to validate all methods parent::__construct ();  The Public Function index () {$notices = $this->user->notices ()->latest ()->get ();//descending order 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 ')); } pubilcfunction confirm (Preparenoticerequest $request) {$template = $this->compiledmcatemplate ($data = $reque       St->all ());       Session ()->flash (' DMCA ', $data); Return view (' Notices.comfirm ', compact (' template '));//Return a new view page to check the completed form data} public function Store () {$this->cre       Aenotice ($request); Mail::queue ([' Text ' = ' EMAILS.DMCA '],compact (' notice '), function ($message) use ($notice) {$message->from ($n Otice->getowneremail ())->to ($notice->getrecipientemail ())->subjeCT (' DMCA Notice ');       }) Flash (' Your DMCA notice has been delivered! ');  Return redirect (' notices ');       The Public Function update ($noticeId,) {$isRemoved = $request->has (' content_removed ');       Notice::findorfail ($noticeId)->update ([' content_removed ' + $isRemoved]);  Return Redirect ()->back ();          The Public Function compiledmcatemplate ($data) {$data = $data + [' name ' = = $this->user->name, ' Email ' + $this->user->email,];//for the template incoming data, splicing data return view ()->file (App_path (' Http/templates  /dmca.blade.php '), $data); } Private Function Createnotice (Request $request) {$notice = Session ()->get (' DMCA ') + [' template ' = + $reque       St->input (' template ')];       $notice = $this->user->notices ()->save ($notice);  return $notice;  } }

The author then removes the Submit key

4. Use JavaScript to implement the above features, briefly showing the code here.

Add custom JavaScript code for app.blade.php

 
    
  
     
   
      
    
       
     
      Dmcaapp   
     
      
       
        @include (' flash::message ')  @include (' Partial.nav)//load navigation bar   @yield (' content ')//content Insertion        
     
      
    
     
   
    
  
   
 
  

Modify index.blade.php Add asynchronous communication, prompt message, 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

Summarize

The Laravel framework shows excellent legibility features, the level of this article is limited to brief details please continue to learn related 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.