コメントアウトは{{– –}}
@forelse, @emptyで出し分け出来る。
<ul> {{-- @foreach ($posts as $post) <li><a href="">{{ $post->title }}</a></li> @endforeach --}} @forelse ($posts as $post) <li><a href="">{{ $post->title }}</a></li> @empty <li>No posts yet</li> @endforelse </ul>
class PostsController extends Controller { // public function index(){ // $posts = Post::orderBy('created_at', 'desc')->get(); // $posts = Post::latest()->get(); $posts = []; // dd($posts->toArray()); // dump die // return view('posts.index', ['posts' => $posts]); return view('posts.index')->with('posts', $posts); } }
ぎゃー