-3

I'm using Laravel 5.1 Im having issues to see my index.html view after i created my home, can see my db saving the data but i can't see it on my web app. I've been using Laravel 5.3 last week and now coming back to 5.1 is actually being harder than before.. I don't know if the problem is in the redirection to my view with the $home

My HomeController:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Flash;
use File;
use App\Home;

class HomeController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $homes = Home::all();

        return view('home.index')->with("homes", $home);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('home.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {

        $data = $request->all();
        $image = $request->file('image');

        if($image)
        {
            $data['image'] = $image->getClientOriginalName();
        }

        $home = new Home($request->all());
        $home->fill($request->all());
        $home->image = $data['image'];
        $home->save();

        if($home->image){
            $path = public_path() . '/image/homes/' . $home->id;
            if( ! File::exists($path)) {
                File::makeDirectory($path, 0775, true, true);
            }
            $imageName = $home->image;
            $request->file('image')->move($path, $imageName);

        }
        flash('Se ha agregado un nuevo slider con exito', 'success');
        return redirect()->route('home.index');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $home = Home::find($id);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $home = Home::find($id);

        return view('home.edit')->with('home', $home);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $data = $request->all();
        $image = $request->file('image');

        if($image)
        {
            $data['image'] = $image->getClientOriginalName();
        }

        $home = new Image($request->all());
        $home->fill($request->all());
        $home->image = $data['image'];
        $home->save();

        if($home->image){
            $path = public_path() . '/image/homes/' . $home->id;
            if( ! File::exists($path)) {
                File::makeDirectory($path, 0775, true, true);
            }
            $imageName = $home->image;
            $request->file('image')->move($path, $imageName);

        }


        Flash::info("El slider ha sido editado con exito!");
        return redirect()->route('home.index');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $path = '/image/homes' . $id;
        $home = Home::find($id);
        $this->deleteFile($path . '/' . $home->image);
        $home->delete();

        Flash::error('El slider ha sido eliminado con exito!');
        return redirect()->route('home.index');
    }
}
tereško
  • 58,060
  • 25
  • 98
  • 150
Julian Moreira
  • 129
  • 1
  • 5
  • 14

1 Answers1

0

Pretty straightforward, this one:

$homes = Home::all();

return view('home.index')->with("homes", $home);

Change $homes to $home, or change $home, to $homes. up to you.

Ohgodwhy
  • 49,779
  • 11
  • 80
  • 110