繁体   English   中英

如何在laravel数据库的表中为经过身份验证的用户存储存储数据

[英]how to get data stored for an authenticated user store in a table in a database in laravel

我正在尝试在我的控制器中使用此代码检索数据以在我的blade.php 文件中创建一个 foreach 表

<?php

namespace App\Http\Controllers;

use illuminate\Http\Resquest;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\user;
use DB;
use Auth;


use Illuminate\Http\Request;

class HistoryController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }

    public function show($user)
    {

        $user_id = auth()->user()->id;

        $history = DB::table('funds')->where('user_id', $user_id);

        return view('history.index')->with('funds',$history);
    }
}

请我需要帮助理解在获取数据时使用数据库查询构建器的概念

使用get()

    public function show($user)
    {

        $user_id = auth()->user()->id;

        $history = DB::table('funds')->where('user_id', $user_id)->get();


        return view('history.index')->with('funds',$history);

    }

或者

return view("history.index", compact("history "));

或者

$history = DB::table('funds')->select('bankname')->where('user_id', $user_id)->get();

刀片.php

@foreach($history as $item)
{
    <p>{{$item->bankname}}</p>
    <p>{{$item->updated_at}}</p>
}

控制器

public function show($user)
{

    $user_id = auth()->user()->id;

    $history = DB::table('funds')->where('user_id', $user_id)->get();

    return view('history.index', compact('history'));
}

在您的刀片中,只需在 foreach 中使用变量$history

刀刃

@foreach($history as $item)
{
    <p>{{$item->bankname}}</p>
    <p>{{$item->updated_at}}</p>
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM