Laravel 在回购或实体的索引中添加列,否则
Laravel add columns in the index in repo or entity or else
我有以下文件,我想创建一个索引 blade,其中的列由 object 提供。用 Id
、Title
、Description
和 Remove
存储数组或 object 的最佳位置是什么,这样我就可以提供 index.blade.php
文件:
BannerController
Banner.php - entity
BannerModel.php
BannerRepository.php interface
EloquentBannerRepository.php
Index.blade.php
@extends('layouts.cms')
@section('title', 'Banners')
@section('content')
<table class="table table-striped">
<thead>
<tr>
<th>Id</th><---This
<th>Title</th><---This
<th>Description</th><---This
<th>Remove</th><---This
</tr>
</thead>
<tbody>
etc etc
首先您需要将项目集合传递给视图
public function index()
{
$items = Item::all(); // it's just an example, get the collection of items however you want
return view('view.name',compact('items'));
}
然后在 index.blade.php 字段中你可以这样做:
@foreach($items as $index=>$item)
<tr>
<td>{{ $index+1 }}</td>
<td>{{ $item->title}}</td>
<td>{{ $item->description}}</td>
<td>
<a href="{{ route('items .edit',$item) }}"><i class="fa fa-pencil glyphicon-edit"></i></a>
<a href="{{ route('items .destroy',$item) }}"><i class="glyphicon glyphicon-trash"></i></a>
</td>
</tr>
@endforeach
我有以下文件,我想创建一个索引 blade,其中的列由 object 提供。用 Id
、Title
、Description
和 Remove
存储数组或 object 的最佳位置是什么,这样我就可以提供 index.blade.php
文件:
BannerController
Banner.php - entity
BannerModel.php
BannerRepository.php interface
EloquentBannerRepository.php
Index.blade.php
@extends('layouts.cms')
@section('title', 'Banners')
@section('content')
<table class="table table-striped">
<thead>
<tr>
<th>Id</th><---This
<th>Title</th><---This
<th>Description</th><---This
<th>Remove</th><---This
</tr>
</thead>
<tbody>
etc etc
首先您需要将项目集合传递给视图
public function index()
{
$items = Item::all(); // it's just an example, get the collection of items however you want
return view('view.name',compact('items'));
}
然后在 index.blade.php 字段中你可以这样做:
@foreach($items as $index=>$item)
<tr>
<td>{{ $index+1 }}</td>
<td>{{ $item->title}}</td>
<td>{{ $item->description}}</td>
<td>
<a href="{{ route('items .edit',$item) }}"><i class="fa fa-pencil glyphicon-edit"></i></a>
<a href="{{ route('items .destroy',$item) }}"><i class="glyphicon glyphicon-trash"></i></a>
</td>
</tr>
@endforeach