Laravel无法显示所选的产品详细信息

时间:2018-02-08 15:17:38

标签: laravel object view product details

也许有人可以帮助我。我已经从我的数据库中完成了产品列表。它显示产品图像,标题,内容,价格 当我选择其中一个产品时,它会在新窗口中打开。我无法看到任何产品细节(没有图像,没有标题,没有内容),只是空白页面。 查看所有附件: 我的 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>

1 个答案:

答案 0 :(得分:1)

因为你做了

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

您需要获取的变量的名称是产品

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