使用Slug(Laravel 5.3)后检索数据时出错

阿里安多·米勒(Ariando Miller)

我在访问使用slug url的页面时遇到问题,以前仅使用id时就可以正常工作。

路线 : Route::get('journal/{journalslug}', 'JournalController@show');

网址: href="{{ url('journal/' . $journal->journalslug) }}

控制器 :

public function show($journalslug) {
        $journal = Journal::where('journalslug','=',$journalslug)->get();
        return view('journal/show', compact('journal', $journal));
    }

看法 :

<div class="large-widget m30">
                    <div class="post-desc">
                        <h2 style="text-align: center;">{{ $journal->title }}</h2>
                        <p style="text-align: center;"><strong>
                                @foreach($journal->user as $item)
                                {{ $item->name }},
                                @endforeach
                        </strong></p>
                        <p style="text-align: center;"><strong>Abstract :</strong></p>
                        <p>{!! $journal->abstract !!}</p>
                        <p style="text-align: center;"><a href="{{ asset('jurnal/' . $journal->file) }}" style="color : #00569d;">View Journal</a></p>
                    </div><!-- end post-desc -->
                </div><!-- end large-widget -->

错误 :

Undefined property: Illuminate\Database\Eloquent\Collection::$title (View: C:\xampp\htdocs\2mark\resources\views\journal\show.blade.php)

我不知道我做错了什么,需要您的帮助,谢谢!

金鳞拉里(Kinshuk lahiri)

更改为:

   $journal = Journal::where('journalslug','=',$journalslug)->first();

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章