Omnis voluptatem quam dignissimos voluptatem cumque nemo.
Laravel fournie une fonction pour debug, elle va afficher toutes les informations sur une variable, tableau... Cette fonction est dd.
(DD = die and dump)
dd($posts);
$posts = Post::all();
return view('accueil', compact('posts'));
<!-- Si il y a des articles -->
@if (count($posts) > 0)
@foreach ($posts as $post)
<h2>{{ $post->title }}</h2>
@endforeach
<!-- Si il n'y a pas d'article -->
@else
<p>Aucun article</p>
@endif
// Récupération du post qui a l'id 1
$posts = Post::find(1);
// trouver un article par son id
$posts = Post::findorfail(81);
Si la condition n'est pas remplie, il va renvoyer une erreur 404.
$posts = Post::orderby('title');
// trouver un article par son title
$posts = Post::where('title', '=', 'Omnis voluptatem quam dignissimos voluptatem cumque nemo.')->firstorfail();