I'm trying to pass to a view, data coming from two unrelated tables. Only the data of one appears, the other is invisible, but you can see the change in the layout when this data is loaded. Another fact that I found curious, is that it is not giving error.
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('/');
}
ChurchController
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, thank you in advance.