2017-02-18 23 views
-2

Я использую Laravel 5.1 У меня возникают проблемы с просмотром моего index.html представления после того, как я создал свой дом, могу видеть, что мой db сохраняет данные, но я не могу см. его в моем веб-приложении. Я использую Laravel 5.3 на прошлой неделе, а теперь вернусь к 5.1 на самом деле сложнее, чем раньше. Я не знаю, является ли проблема в перенаправлении на мой взгляд с помощью $ homeОшибкаException в HomeController.php строка 23: Неопределенная переменная: 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'); 
    } 
} 
+0

'$ home' =/=' $ homes' ПРОСТОТЫ – RiggsFolly

ответ

0

Довольно просто, это один:

$homes = Home::all(); 

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

Изменение $homes в $home или изменить $home, к $homes. вам решать.

+0

Это должно быть VTC для опечатки. – miken32

+0

Спасибо, сэр! Im dumb haha –