-1
I plan to replace the Welcome view with another one I created with a controller. For better understanding, here’s my attempt that’s not working:
Route
Route::get('/portal', 'portal\SiteController@index');
Controller
public function getPostsCarousel() //Busca os posts para o carousel
{
return Post::orderBy('id', 'DESC')->take(5)->get();
}
public function getPostsSite() //Busca os posts que ficam abaixo do carousel
{
return Post::orderBy('id', 'DESC')->take(6)->get();
}
Sitecontroller
public function index()
{
return view('portal.home')
->with('postCarousel', $this->getPostsCarousel())
->with('postsSite', $this->getPostsSite());
}
home view
@extends('portal.welcome')
@section('conteudo')
<div>
<div id="carousel-example-generic" class="carousel slide carousel-home" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
@foreach($postCarousel as $postCar)
{{--<li data-target="#carousel-example-generic" data-slide-to="{{$i}}"></li>--}}
<li data-target="#carouselExampleIndicators" data-slide-to="{{ $loop->index }}" class="{{ $loop->first ? 'active' :'' }}"></li>
@endforeach
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
@foreach($postCarousel as $item)
<div class="item {{ $loop->first ? 'active' : '' }}">
<img src="{{$item->imagem}}" alt="...">
<div class="carousel-caption" style="background-color: rgba(133,178,0,0.7)">
<p><h3>{{$item->titulo}}</h3></p>
</div>
</div>
@endforeach
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<div class="homeNotic">
<hr>
<div class="row">
@foreach ($postsSite as $key =>$value)
<div class="col-sm-3 col-md-4">
<div class="thumbnail">
<img src="{{$value->imagem}}" alt="{{$value->titulo}}">
<div class="noticia-titulo-home" >
<p class="titVisualizado"><b>{{$value->titulo}}</b></p>
</div>
<div class="noticia-conteudo-home">
<p class="contVisualizado">{{$value->descricao}}</p>
</div>
<div class="caption" style="height: 20px; padding: 5px" >
<p>
<a href="{{url('visualizar-noticia/'.$value->id)}}" class="btn btn-success" role="button">Ler Mais</a>
</p>
</div>
<div class="caption" style="height: 25px; padding: 5px" >
<p>
<span class="pull-right" style="color: #e38d13">{{$value->created_at->diffForHumans()}}</span>
</p>
</div>
</div>
</div>
@endforeach
<p>
<a style="width: 100%; font-size: 14pt" href="{{url('index-noticia')}}" class="btn btn-success" role="button">VER MAIS NOTÍCIAS <i class="glyphicon glyphicon-forward"></i></a>
</p>
</div>
</div>
</div>
@endsection
And I’m getting the following mistake:
Notfoundhttpexception in Routecollection.php line 161:
I’ve also tried to change course to:
Route::get('/', function (){
return view('portal.home');
});
And made the following mistake:
Errorexception in 2574245cf5e2373fc28372419f83853770ad5aae.php line 8: Undefined variable: postCarousel (View: C: xampp htdocs GEIGRE_WEB5_3 Resources views portal home.blade.php)