Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何仅在laravel中的前一周记录上添加编辑按钮_Laravel_Eloquent - Fatal编程技术网

如何仅在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>