Skip to content

Commit

Permalink
#4 - Affichage des données stockées
Browse files Browse the repository at this point in the history
  • Loading branch information
alexis-riot committed Feb 27, 2020
1 parent f08dd28 commit 85c0ee9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
4 changes: 3 additions & 1 deletion project/app/Http/Controllers/IndexController.php
Expand Up @@ -2,12 +2,14 @@

namespace App\Http\Controllers;

use App\Post;
use Illuminate\Http\Request;

class IndexController extends Controller
{
public function index()
{
return view('index');
return view('index')
->with('posts_list', Post::all());
}
}
34 changes: 22 additions & 12 deletions project/resources/views/index.blade.php
Expand Up @@ -3,21 +3,31 @@
@section('content')
<div class="container">
<div class="row mb-2">
<!-- Post 1 -->
<div class="col-md-6">
<div class="row border mb-4 shadow-sm h-md-250">
<div class="col p-4 d-flex flex-column position-static">
<h3 class="mb-0">Title</h3>
<div class="mb-1 text-muted">Date</div>
<p class="card-text mb-auto">Some content limited to 200 characters...</p>
<a href="#" class="stretched-link">Voir le post</a>
@if ($posts_list->count() > 0)
@foreach ($posts_list as $post)
<!-- Post {{ $post->id }} -->
<div class="col-md-6">
<div class="row border mb-4 shadow-sm h-md-250">
<div class="col p-4 d-flex flex-column position-static">
<h3 class="mb-0">{{ $post->title }}</h3>
<div class="mb-1 text-muted">{{ $post->created_at->diffForHumans() }}</div>
<p class="card-text mb-auto">{!! Str::limit($post->content, 200, ' ...') !!}</p>
<a href="#" class="stretched-link">Voir le post</a>
</div>
<div class="d-lg-block">
<img class="bd-placeholder-img" width="200" height="250" src="https://www.webnode.com/blog/wp-content/uploads/2016/10/Blog-intro.jpg">
</div>
</div>
<div class="d-lg-block">
<img class="bd-placeholder-img" width="200" height="250" src="https://www.webnode.com/blog/wp-content/uploads/2016/10/Blog-intro.jpg">
</div>
<!-- End Post {{ $post->id }} -->
@endforeach
@else
<div class="col-md-12">
<div class="alert alert-info" role="alert">
Aucun post n'a été publié sur le blog!
</div>
</div>
</div>
<!-- End Post 1 -->
@endif
</div>
</div>
@endsection

0 comments on commit 85c0ee9

Please sign in to comment.