0
I want to take the last five images in the bank and show them on a carousel, with the respective title, and those marks that indicate the image being viewed. I’m working with Laravel 5.1 and mysql. For further clarification, here are some tips:
To fetch the 5 records (getNoticia)
Controller.php
abstract class Controller extends BaseController
{
use DispatchesJobs, ValidatesRequests;
protected function getLemas() {
return Lema::where('status_lm', 'Activo')->get();
}
protected function getIgreja() {
return Igreja::All();
}
protected function getNoticia() {
return Noticia::all()->take(5);
}
}
Noticiacontroller.php
class NoticiaController extends Controller
{
// Display a listing of the resource.
// @return \Illuminate\Http\Response
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('noticias.create-noticia')->with('lema', $this->getLemas())->with('igreja',$this->getIgreja());
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
if($request->hasFile('imagem'))
{
$imagem = $request->file('imagem');
$extensao = $imagem->getClientOriginalExtension();
if($extensao != 'jpg' && $extensao != 'jpeg' && $extensao != 'png')
{
return back()->with('erro','Erro: Este arquivo não é uma imagem JPG ou PNG');
}
}
$noticia = new Noticia();
$noticia->titulo = $request->titulo;
$noticia->conteudo = $request->conteudo;
$noticia->imagem = "";
$noticia->save();
if(Input::file('imagem'))
{
File::move($imagem,public_path().'/imagem-noticia/noticia-id_'.$noticia->id.'.'.$extensao);
$noticia->imagem = '/imagem-noticia/noticia-id_'.$noticia->id.'.'.$extensao;
$noticia->save();
}
return redirect('/');
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
Just to point out that in Noticiacontroller.php, I didn’t implement anything for that same search, because I don’t know how to do it. I’ve searched so much, but I haven’t found a subject that can help me.
Homecontroller.php
class HomeController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('home')
->with('lema', $this->getLemas())
->with('igreja',$this->getIgreja())
->with('noticia',$this->getNoticia());
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
View Home.blade.php
<div id="carousel-example-generic" class="carousel slide carousel-home" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="/imagem-noticia/noticia-id_11.jpg" alt="...">
<div class="carousel-caption" style="background-color: rgba(4,162,183,0.9)">
<p><h3>Preparativos para o 2º Aniversário da Igreja</h3></p>
</div>
</div>
<div class="item">
<img src="/imagem-noticia/noticia-id_12.jpg" alt="...">
<div class="carousel-caption" style="background-color: rgba(4,162,183,0.9)">
<p><h3>Coral das moças estará na Igreja Baptista da Paz</h3></p>
</div>
</div>
<div class="item">
<img src="/imagem-noticia/noticia-id_13.jpg" alt="...">
<div class="carousel-caption" style="background-color: rgba(4,162,183,0.9)">
<p><h3>EBF - Inscrições Abertas</h3></p>
</div>
</div>
</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>
In this view, I did not put the carousel to take the data dynamically in the database, but rather to take the images from a folder, as shown in the following image.
When in fact, my purpose is to load the data dynamically and present them on the carousel (slides).
The page looks like this
You made the model? you have the table name if you didn’t make the model? and you made the code in which controller you can make available?
– novic
I just edited @Virgilionovic
– Daniel dos Santos
return Noticia::all()->take(5);
would be on that line ?– novic
I didn’t get it. Would that be?
– Daniel dos Santos
then you want to return the last record of the model Noticia? and it is on this line ???
– novic
Yes, that’s right. What would it be like?
– Daniel dos Santos