Route::get('/', 'IndexController@index')->name("home");
Route::get('/article/{id}', 'ArticleController@index')->name('article');
class ArticleController extends Controller
{
public function index($id)
{
$article = Article::query()->select('*')->where('id', $id)->get();
return view('default.articles.news', ['article' => $article]);
}
}
class IndexController extends Controller
{
private $perPage = 9;
public function index()
{
$articles = Article::query()->select('*')->paginate($this->perPage);
return view('index', ['articles' => $articles]);
}
}
@section('mainContent')
<div class="container">
<div class="row mt-4 d-flex justify-content-between">
@foreach($articles as $article)
<div class="card-deck col-sm-12 col-md-6 col-lg-4 col-xl-4 mt-2 mb-4">
<div class="card">
<img class="card-img-top rounded-top" height="190" src="{{ $article->poster }}">
<div class="card-body">
<h5 class="card-title"><a href="{{ route('article', ['id' => $article->id]) }}">{{ $article->title }}</a></h5>
<p class="card-text" style="color: #000000">{{ $article->preview }}</p>
</div>
<div class="card-footer">
<small class="text-muted">Дата публикации: {{ $article->created_at }}</small>
</div>
</div>
</div>
@endforeach
@if(count($articles) > $articles->perPage())
<div class="container">
<div class="row d-flex justify-content-center mt-2 mb-2">
{{ $articles->links() }}
</div>
</div>
@endif
</div>
</div>
@endsection
@extends('index')
@section('mainContent')
{{ $article }}
@endsection
Undefined variable: articles
(View: C:\Web\MyHost\laravel\resources\views\index.blade.php)
(View: C:\Web\MyHost\laravel\resources\views\index.blade.php)
class ArticleController extends Controller
{
public function index($id)
{
$article = Article::query()->select('*')->where('id', $id)->first();
return view('default.articles.news', ['article' => $article]);
}
}
use App\Article;
class ArticleController extends Controller
{
public function index(Article $article)
{
return view('default.articles.news', ['article' => $article]);
}
}