I'm having the following error message in my project:
Undefined variable: banner (View: C: \ wamp64 \ www \ panelEda \ resources \ views \ alter-banner.blade.php)
While in my view banner.blade.php
looks like this:
<div class="row">
<div class="col-12">
<form method="post" action="{{ route('banner.update', $banner->id) }}" enctype="multipart/form-data">
{{ method_field('PUT') }
{{ csrf_field() }}
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-lg-12">
<div class="form-row">
<div class="form-group col-lg-9">
<label for="simpleinput">Título</label>
<input type="text" value="{{ $banner->titulo or old('titulo') }}" id="simpleinput" class="form-control" name="titulo">
</div>
<div class="form-group col-lg-3">
<label for="example-date">Texto</label>
<input class="form-control" value="{{ $banner->imagem or old('imagem') }}" id="example-date" type="date" name="imagem">
</div>
</div>
<div class="form-row">
<div class="form-group col-lg-12">
<input class="form-control" value="{{ $banner->descricao or old('descricao') }}" name="descricao"></textarea>
</div>
</div>
</div>
</div>
</div>
</div>
The controller looks like this:
public function index(){
$banners = Banner::all();
$total = Banner::all()->count();
return view('banner', compact('banners', 'total'));
}
public function create(){
return view('adicionar-banner');
}
public function store(Request $request){
$banners = new Banner;
$banners->titulo = $request->titulo;
$banners->descricao = $request->descricao;
$banners->imagem = $request->imagem;
$banners->save();
return redirect()->route('banner.index')->with('message', 'Banner publicado com sucesso!');
}
public function show($id) {
}
public function edit($id) {
$banners = Banner::findOrFail($id);
return view('alterar-banner', compact('banner'));
}
public function update(Request $request, $id) {
$$banners = Banner::findOrFail($id);
$banners->titulo = $request->titulo;
$banners->descricao = $request->descricao;
$banners->save();
return redirect()->route('banner.index')->with('message', 'Banner alterado com sucesso!');
}
Where am I going wrong?