【发布时间】:2020-04-13 08:21:31
【问题描述】:
当我观看 youtube Laravel From Scratch [Part 6] - Fetching Data With Eloquent 时,我看到他在不使用 if 语句和 foreach 的情况下将数据传递给查看,我已经尝试过但没有工作
public function show(todo $todo)
{
$todo=todo::find($todo);
return view('demo')->with('todo',$todo);
}
我的观点没有 if 语句和 foreach
@extends('layouts.app')
@section('content')
{{$todo->note}}
@endsection
我在使用 if 语句和 foreach 时的看法
@extends('layouts.app')
@section('content')
@if (count($todo) > 0)
@foreach ($todo as $item)
{{$item->note}}
@endforeach
@endif
@endsection
我收到了一个错误
Property [note] does not exist on this collection instance
https://www.youtube.com/watch?v=emyIlJPxZr4&list=PLillGF-RfqbYhQsN5WMXy6VsDMKGadrJ-&index=6
【问题讨论】:
-
你能做
return $todo;并提供结果吗? -
顺便说一句,他在视频中间同时使用了 if 语句和 foreach。
-
在视频中11:51和12:01,他没有使用if语句和foreach,然后他刷新页面,它仍然得到数据
-
这是两个不同的页面两个刀片文件,一个是显示所有帖子的索引,第二个是显示刀片文件,它显示单个帖子。所以你不需要 foreach 和 if。
-
我尝试了相同的代码,但结果不一样