上一篇讲了Laravel创建产品-CRUD之Create and Store,现在我们来做产品展示模块,用到是show,①首先我们先修改controller,文件是在/app/Http/Controllers/ItemController.php,定义一下show function
public function show($id) { $item = Item::find($id); return view(‘items.show‘)->with(‘item‘, $item); }
②创建show模板,文件是/resources/views/items/show.blade.php,添加如下代码
@extends(‘layouts.app‘) @section(‘content‘) <div class="container"> <div class="row"> <div class="col-md-12"> <div class="card"> <div class="card-header">Item:{{$item->id}}</div> <div class="card-body"> <div class="col-md-8" style="float: left;"> <div class="form-group row"> <label>ID:</label> <div class="col-md-6">{{$item->id}}</div> </div> <div class="form-group row"> <label>Name:</label> <div class="col-md-6">{{$item->name}}</div> </div> <div class="form-group row"> <label>Price:</label> <div class="col-md-6">{{$item->price}}</div> </div> <div class="form-group row"> <label>Description:</label> <div class="col-md-6">{{$item->description}}</div> </div> </div> <div class="col-md-4" style="float: left;"> <dl class="well"> <label>Created At:</label> <div>{{$item->created_at}}</div> <label>Updated At:</label> <div>{{$item->updated_at}}</div> </dl> <div class="row"> <div class="col-md-6"> <a class="btn btn-primary" href="{{route(‘items.edit‘, $item->id)}}">edit</a> </div> <div class="col-md-6"> <a class="btn btn-danger" href="{{route(‘items.destroy‘, $item->id)}}">delete</a> </div> </div> </div> </div> </div> </div> </div> </div> @endsection
原文地址:https://www.cnblogs.com/ytkah/p/9290672.html
时间: 2024-10-21 06:35:16