Laravel Small Item 8th section laravel-the form to view the details and remove 8.1 add links to HTML __html

Source: Internet
Author: User
section 8th laravel-the form to view details and delete
8.1 Add links to HTML
8.2 Implementation View Details
8.3 implementation Delete
8.1 Adding links to HTML

as follows, modify the view file, add link address details Modify Delete

To add a route:

Route::any (' Student/detail/{id} ', [' Uses ' => ' studentcontroller@detail ']);
Route::any (' Student/delete/{id} ', [' Uses ' => ' studentcontroller@delete ']);

Create View Details Page view \resources\views\student\detail.blade.php

@extends (' layout/student ') @section (' content ') <!--custom content area--> <div class= "Panel Panel-default" > <div class= "panel-heading" > Student details </div> <table class= "Table table-bordered table- Striped Table-hover "> <tbody> <tr> <td wid
                   Th= "50%" >ID</td> <td>1</td> </tr>
                   <tr> <td> name </td> <td>sean</td> </tr> <tr> <td> Age </td> <td >18</td> </tr> <tr> <td> gender </td&
                       Gt <td> men </td> </tr> <tr> <td> AddDate </td> <td>2016-01-01</td> </tr>
                   ;tr> <td> Final Modification </td> <td>2016-03-01</td>
 </tr> </tbody> </table> </div> @endsection
8.2 Implementation View Details

To create a detail method in a controller:

/**
 * View user information based on ID * *
 @param
 * @return    void
 * @author    webjust [604854119@qq.com]
 * * Public
function Detail ($id)
{
    $student = Student::find ($id);

    Return view (' Student/detail ', [' Student ', $student]);
}

To render a variable in a view: \resources\views\student\detail.blade.php

<?php use app\models\student; $students = new Student ()?> @extends (' layout/student ') @section (' content ') <!--custom content area--> &LT;DIV cl ass= "Panel Panel-default" > <div class= "panel-heading" > Student details </div> <table class= "table table-bordered table-striped table-hover "> <tbody> <tr> <td
             Width= "50%" >ID</td> <td>{{$student->id}}</td> </tr>
             <tr> <td> name </td> <td>{{$student->name}}</td> </tr> <tr> <td> age </td> <td>{{$stud
                 Ent->age}}</td> </tr> <tr> <td> sex </td> <td>{{$students->sex ($student->sex)}}</td> </tr> <tr> <td> Add date </td> <td>{{date (' y-m-d ', $student->created_time
                 )}}</td> </tr> <tr> <td> Final modification </td> <td>{{date (' y-m-d ', $student->updated_time)}}</td> </tr> </tbody&gt
         ;
 </table> </div> @endsection
8.3 Implementation Deletion

To implement the delete operation in the controller:

/** *
 Delete operation
 *
 @param
 * @return    void
 * @author    webjust [604854119@qq.com]
 / Public
function Delete ($id)
{
    $student = Student::find ($id);

    if ($student->delete ())
    {return
        redirect ('/')->with (' Success ', ' Delete succeeded-'. $id);
    } else {
        Return Redirect ()->back ()->with (' Error ', ' Delete failed-'. $id);
    }
}

When you delete, add a prompt window:

<a onclick= "If" (Confirm (' Confirm deletion? ') = = false) return false; " 
href= ' {{URL (' student/delete ', [' id ' => $student->id]}} ' > Delete </a>

Effect Display:

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.