【问题标题】:Laravel cannot display a selected product detailsLaravel 无法显示选定的产品详细信息
【发布时间】:2018-02-08 15:17:37
【问题描述】:

也许有人可以帮助我。我已经从我的数据库中完成了一个产品列表。它显示产品图片、标题、内容、价格 当我选择其中一种产品时,它会在新窗口中打开。而且我看不到任何产品详细信息(没有图像,没有标题,没有内容),只是空白页面。 查看所有附件: 我的 BrackController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\file;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Collection;

class BracController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('insertBrac');
    }

    public function showBrac()
    {
        $user=file::all();
        return view('apyrankes', compact('user'));
    }

    public function view_brac()
{
    $object = \DB::table('braclets')->where('BrackID' , request('brackId'))->first();
    return view('view_object', array('user' => $object));
}

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        {
        $user = new file;

        $user->Title= Input::get('title');
        $user->Content= Input::get('content');
        $user->Price= Input::get('price');
        if (Input::hasFile('image'))
            {
                $file=Input::file('image');
                $file->move(public_path(). '/uploads', $file->getClientOriginalName());

                $user->Image = $file->getClientOriginalName();
            }

        $user->save();

        return redirect( "insertBrac" );

     }
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}

我的产品列表: apyrankes.blade.php

<div class="header">
    @include('header')
</header>
<body>
        <div class="content-products">
                    @foreach($user as $users)
                    <div id="myDiv">
                        <div class="products">
                            <img src="{{ $users->Image}}" alt="{{ $users->Title}}" width="200px" height="200px"><br>
                            {{ $users->Title}}<br>
                            {{ $users->Content}}<br>
                            {{ $users->Price}}€<br>
                            <a href="view_object?product={{ $users->BrackID }}">Plačiau</a>
                        </div>
                    </div>
                    @endforeach
        </div>


</body>

当我从 apyrankes.blade.php 上的产品列表中选择一种产品时 它在 view_object.blade.php 中打开,但我看不到所选产品的任何详细信息,只是空白页面: 我的 view_object.blade.php

<div class="header">
    @include('header')
</header>
        <body>
            <Br>
            <br>
            <Br>
            <div class="content-products">
                <div id="myDiv">
                    <div class="products">
                        @if($user)
                        <img src="{{ $user->Image}}" alt="{{ $user->Title}}" width="200px" height="200px"><br>
                        {{ $user->Title}}<br>
                        {{ $user->Content}}<br>
                        {{ $user->Price}}€<br>
                        @endif
                    </div>
                </div> 
            </div>         
        </body>

【问题讨论】:

    标签: laravel object view product


    【解决方案1】:

    因为你做到了

    <a href="view_object?product={{ $users->BrackID }}">Plačiau</a></div>
    

    您需要获取的变量名称是product

    $object = \DB::table('braclets')->where('BrackID' , request('product'))->first();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-13
      • 1970-01-01
      • 1970-01-01
      • 2020-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多