My index is giving a return of Undefined variable: image

Asked

Viewed 45 times

0

I created my index so only that it is returning an error in the view to get the image : Undefined variable: image (View: /var/www/html/fernandosite/Resources/views/admin/marcadaguas/index.blade.php)

      @foreach($imagem as $image)
          <tr>
            <td class="text-my-color-4">
              {{ $image->id }}
            </td>
            <td class="text-my-color-4">
              <img src="{{$image->imagem}}" class="rounded img-fluid" style="height: 50px;">
            </td>
          </tr>
        @endforeach

and in my controller is the index:

public function index()
    {
        return view('admin.marcadaguas.index')->with('imagem', Marcadagua::all());
    }

In my store it’s like this:

public function store(Request $request)
    {
        
        $this->validate($request,[
            'imagem' => 'required|image',
            'perfil' => 'required|image',
            'logomarca' => 'required|image',
            'nome' => 'required',
        ]);

        $imagem = $request->file('imagem');
        $filename = time() . '.' . $imagem->getClientOriginalExtension();

        $perfil = $request->file('perfil');
        $filename = time() . '.' . $perfil->getClientOriginalExtension();

        $logomarca = $request->file('logomarca');
        $filename = time() . '.' . $logomarca->getClientOriginalExtension();

        $nome = $request->nome;
       
        $imagem = Image::make($imagem)->fit(1080,720);
        $perfil = Image::make($perfil)->fit(140,140);
        $logomarca = Image::make($logomarca)->fit(140,140);
        
        Image::make($imagem)->insert($perfil, 'top-left', 0,15)->insert($logomarca, 'bottom-left', 0,5)->insert(public_path('marcadagua/principal.png'), 'bottom-left', 0, 0)
        ->text($nome, 70, 170, function($font) {
            $font->file('marcadagua/RobotoCondensed-Bold.ttf');
            $font->size(15);
            $font->color('#2BB7C4');
            $font->align('center');
            $font->valign('top');
        })->save('uploads/posts/' . $filename );

       $imagem = Marcadagua::create([ 
        'imagem' => 'uploads/posts/' . $filename,

        ]);

        Session::flash('success', 'Post criado com sucesso.');
        
        return view('admin.marcadaguas.index');
    }

1 answer

0

Its function store is not sending any variable call image for your view. Try to return the route to your controller accessing the function index at the end of its function store, something like:

    public function store(Request $request){
       ...
       return route(rota.para.index.controller);
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.