mercredi 3 juin 2020

Trying to get property 'photo' of non-object

When I implemented the create view it worked fine, but after implementing the show view it stopped working throwing the following error:

Facade\Ignition\Exceptions\ViewException Trying to get property 'foto' of non-object (View: C:\xampp\htdocs\alme\resources\views\aluminio\show.blade.php) http://127.0.0.1:8000/aluminio/create

AluminioController.php

    {
        $productos = Aluminio::all();
        return view('aluminio.index',compact("productos"));
    }

    public function show($id)
    {
        $productos =Aluminio::find($id);
        return view('aluminio.show', compact('productos'));
    }

    public function create()
    {
        return view('aluminio.create');
    }

    public function store(Request $request){

        $productos = $request->all();

        if($request->hasFile('foto')){
            $productos['foto']=$request->file('foto')->store('uploads','public');
        }        
        Aluminio::create($productos);

        return redirect(route('aluminio'));
    }

web.php

Route::get('aluminio', 'AluminioController@index')->name('aluminio');
Route::get('aluminio/{id}', 'AluminioController@show')->name('aluminio.show');
Route::get('aluminio/create', 'AluminioController@create')->name('aluminio.create');
Route::post('aluminio', 'AluminioController@store')->name('aluminio.store');

create.blade.php

@section('contenido')
            <div class="content-fluid">

                <div class="row justify-content-center">
                <form action="" method="post" enctype="multipart/form-data">
                  @csrf
                      <div class="col-10">
                        <div class="form-group">
                          <label  for="tipologia" class="control-label">Tipología</label>
                          <input type="text" class="form-control" name="tipologia" id="tipologia">
                          </div>
                          <div class="form-group">
                          <label  for="caracteristicas" class="control-label">Características</label><br>                            
                          <textarea name="caracteristicas" id="caracteristicas" cols="30" rows="10"></textarea>
                          </div>
                          <div class="form-group">
                          <label  for="foto" class="control-label">Foto</label>                           
                          <input type="file" class="form-control" name="foto" id="foto">
                          </div>
                          <div class="form-group">
                          <button class="btn btn-primary" type="submit">Crear</button>
                         </div>
                      </div>                       
                    </form>                 
                </div>
            </div>
            @endsection

show.blade.php

@section('contenido')
            <div class="content-fluid">

                <div class="jumbotron">
                    <div class="row">
                        <div class="col-6">
                            <img src="" class="card-img-top" width="100" height="300" alt="...">
                        </div>
                        <div class="col-6">
                            <h1 class="display-4"></h1>
                            <hr class="my-4">
                            <p class="lead"></p>                        
                            <a class="btn btn-primary btn-lg" href="" role="button">Atras</a>

                        </div>
                    </div>


                  </div>
            </div>
            @endsection


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire