-2
I’m getting the following error message in my project:
Undefined variable: banner (View: C: wamp64 www painelEda Resources views alterar-banner.blade.php)
While in my view banner.blade.php
is this way:
<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 is 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?
You are probably not passing the variable
banner
controller for your view. Or the variable name is incorrect. Edit the question and enter the contents of your controller– sant0will
I edited the question and added the controller.
– Lucas Henrique