gpt4 book ai didi

php - 从数据库中检索特定用户的内容

转载 作者:行者123 更新时间:2023-11-29 17:52:15 24 4
gpt4 key购买 nike

我目前正在开发一个 Laravel 项目,我希望用户能够上传各种文件,然后查看他们上传的内容。

目前所有用户都可以看到每个人的上传内容。有没有办法只检索登录用户的上传内容?

我在下面附上了我的 Controller 和blade.php 的图像。

blade.php

查看文件

    <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<style type="text/css">

.wrapper{

margin: 0 auto;
width: 80%;
margin-top: 10px;

}

</style>

</head>

<body>


<div class="wrapper">

<section class="panel panel-primary">

<div class="panel-heading">

<h2> Uploads </h2>

</div>

<div class="panel-body">

<table class="table table-bordered">

<thead>

<th> User </th>
<th> Title </th>
<th> Upload Date & Time </th>
<th> Action </th>

</thead>

<tbody>

@foreach($downloads as $down)


<tr>

<td> {{ Auth::user()->name }} </td>
<td> {{$down->name}} </td>
<td> {{$down->created_at}} </td>
<td>

<a href="ftp://193.61.148.237//public_html/workspace/COM559/prototype/test/storage/app/public/upload/{{$down->name}}"download="{{$down->name}}">

<button type="button" class="btn btn-primary">

<i class="glyphicon glyphicon-download"> Download </i>

</button>

</a>

</td>

</tr>





@endforeach


</tbody>

</table>

</div>

</section>

</div>



</body>

Controller 文件

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use DB;

class Downloadcontroller extends Controller
{


public function downfunc() {


$downloads=DB::table('files')->get();
return view('download.viewfile', compact('downloads'));

}
}

最佳答案

$downloads = DB::table('files')->where('user_id', $userId)->get();

或者对于当前用户,您可以:

$downloads = DB::table('files')->where('user_id', auth()->user()->id)->get();

关于php - 从数据库中检索特定用户的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49211830/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com