1
I’m trying to move to a view, data from two unrelated tables. Appear only the data of one, the other, They are invisible, but you can notice the change in the layout when these data are loaded. Another fact that I found curious, is that there is no mistake.
For better insight, here’s the code:
abstract class Controller extends BaseController
{
use DispatchesJobs, ValidatesRequests;
protected function getLemas() {
return Lema::where('status_lm', 'Activo')->get();
}
protected function getIgreja() {
return Lema::All();
}
}
Lemacontroller
public function create()
{
return view('lema.create-lema')->with('lema', $this->getLemas())->with('igreja',$this->getIgreja());
}
public function store(Request $request)
{
$lema=new Lema();
$lema->texto_lm = $request->texto;
$lema->refBilblica_lm = $request->refBiblica;
$lema->status_lm = $request->status;
$lema->save();
return redirect('/');
}
Igrejacontroller
public function create()
{
return view('igreja.create-igreja')->with('lema', $this->getLemas())->with('igreja',$this->getIgreja());
}
public function store(Request $request)
{
if($request->hasFile('logo'))
{
$logo = $request->file('logo');
$extensao = $logo->getClientOriginalExtension();
if($extensao != 'jpg' && $extensao != 'jpeg' && $extensao != 'png')
{
return back()->with('erro','Erro: Este arquivo não é uma imagem JPG ou PNG');
}
}
$igreja = new Igreja();
$igreja->nome_ig = $request->nome;
$igreja->missao_ig = $request->missao;
$igreja->valores_ig = $request->valores;
$igreja->visao_ig = $request->visao;
$igreja->historial_ig = $request->historial;
$igreja->endereco_ig = $request->endereco;
$igreja->telefone_ig = $request->telefone;
$igreja->telefone1_ig = $request->telefone1;
$igreja->email_ig = $request->email;
$igreja->logo_ig = "";
$igreja->save();
if(Input::file('logo'))
{
File::move($logo,public_path().'/imagem-logo/igreja-id_'.$igreja->id.'.'.$extensao);
$igreja->logo_ig = '/imagem-logo/igreja-id_'.$igreja->id.'.'.$extensao;
//$post->imagem = public_path().'/imagem-post/post-id_'.$post->id.'.'.$extensao;
$igreja->save();
}
return redirect('/');
}
Homecontroller
public function index()
{
return view('home')->with('lema', $this->getLemas())->with('igreja',$this->getIgreja());
}
Route
Route::get('/', 'HomeController@index');
Route::post('criar-lema', 'LemaController@store');
Route::get('criar-lema', 'LemaController@create');
Route::get('criar-igreja', 'IgrejaController@create');
Route::post('criar-igreja', 'IgrejaController@store');
View banner.blade.php
<div class="page-header page-header-home">
<div class="container" style="margin-bottom: 0px; background-color: #85B200">
<?php foreach ($igreja as $key => $value): ?>
<img src="{!! url ($value->logo_ig) !!}" alt="...">
<?php endforeach; ?>
<a href="#"> <i class="glyphicon glyphicon-user" style="float: right; position: relative; margin-top: 100px; margin-right: 20px; color: #FFFFFF">Iniciar Sessão</i></a>
<div style="padding: 2px; background-color: #4C6600; width: 450px; height: 90px; border-radius: 15px; position: relative; float: right; margin-right: 190px; margin-top: 22px">
<?php foreach ($lema as $key => $value): ?>
<p style="padding: 0px; text-align: center; font-family: 'Tw Cen MT', Arial, 'Helvetica LT Std';font-size: 22px; color: #ffffff; line-height: 90%;">{!! $value->texto_lm !!}</p>
<p style="padding: 0px; text-align: center; font-family: 'Tw Cen MT', Arial, 'Helvetica LT Std';font-size: 15px; color: #ffffff; line-height: 90%;">{!! $value->refBilblica_lm !!}</p>
<?php endforeach; ?>
</div>
</div>
</div>
Please, I need help, and I thank you.
Which route are you trying to access?
– PV Telles
The first "Route::get('/', 'Homecontroller@index');"
– Daniel dos Santos
before the Return of your Homecontroller@index method put dd( $this->getLemas()) and then dd($this->getIgreja()), and place the results so we can see what is happening
– PV Telles
Just bringing me the dd($this->getLemas data()).
– Daniel dos Santos
Both dd($this->getLemas()), and dd($this->getIgreja()), are returning me only the data from the table "lemmas".
– Daniel dos Santos
Yes, because $this->getLemas() is returning data from the Lemma table where 'status_lm' is equal to 'Active' and $this->getIgreja() is returning all data from the Lemma table, this is not the behavior you want?
– PV Telles
No. What I want is the $this->getIgreja() to return the data from the "church" table, which contains the logo that has to appear on the banner. And $this->getLemas(), returns the data from the Lemma table where 'status_lm' is equal to 'Active''
– Daniel dos Santos