如何仅在laravel中的前一周记录上添加编辑按钮
我想添加仅适用于前一周记录的删除按钮如何仅在laravel中的前一周记录上添加编辑按钮,laravel,eloquent,Laravel,Eloquent,我想添加仅适用于前一周记录的删除按钮 $accounts = Accounts::orderBy('id', 'desc')->get(); return response()->json($accounts); 谢谢。我相信您希望在视图/表中显示您的帐户 class AccountsController extends Controller { public function index() { $accounts = Accounts::orde
$accounts = Accounts::orderBy('id', 'desc')->get();
return response()->json($accounts);
谢谢。我相信您希望在视图/表中显示您的帐户
class AccountsController extends Controller
{
public function index()
{
$accounts = Accounts::orderBy('id', 'desc')->get();
return view('accounts.index', compact('accounts'));
}
}
我还假设帐户
模型在时间戳处创建了一个,这是一个实例。所以我们可以使用isLastWeek()
方法。在accounts/index.blade.php
中,您可以执行以下操作:
帐户ID
帐户名
行动
@foreach($account作为$account)
{{$account->id}
{{$account->name}
@如果($account->created_at->isLastWeek())Edit@endif
@endforeach
如果要使用Vue,没问题。让我们稍微更新accounts/index.php
:
// accounts/index.blade.php
<accounts-list :accounts="{{$accounts}}"/>
然后我们有AccountsList.vue
组件:
<template>
<table>
<tr>
<th>Account ID</th>
<th>Account Name</th>
<th>Actions</th>
</tr>
<tr is="account-row" v-for="account in accounts" :account="account" :key="account.id"></tr>
@endforeach
</table>
</template>
<script>
import AccountRow from './AccountRow.vue'
export default {
props: ['accounts'],
components: {AccountRow}
}
</script>
您的问题与您的代码不匹配是的,这是我只知道的代码,我不知道如何查询或添加按钮。如何使用vue?@Marky更新了我的答案。希望能回答你的问题。
<template>
<table>
<tr>
<th>Account ID</th>
<th>Account Name</th>
<th>Actions</th>
</tr>
<tr is="account-row" v-for="account in accounts" :account="account" :key="account.id"></tr>
@endforeach
</table>
</template>
<script>
import AccountRow from './AccountRow.vue'
export default {
props: ['accounts'],
components: {AccountRow}
}
</script>
<template>
<tr>
<td>{{account.id}}</td>
<td>{{account.name}}</td>
<td><button v-if="account.created_last_week">Edit</button></td>
</tr>
</template>
<script>
export default {
props: ['account']
}
</script>