samedi 18 février 2017

Class 'App\Http\Controllers\Image' not found - HomeController.php line 53 - Laravel 5.1

This is the error i get when i submit my create code. Looks like my public_path is not being respected by the store function, so it looks for a controller called Image... Hope you guys can help me find out the error.

<?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
{

    public function store(Request $request)
    {

        $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::success("Se ha agregado un nuevo slider con exito");
        return redirect()->route('home.index');
    }
}

My public path is -> public/image/homes

Create function:

@section('main-content')
<div class="container">
    <div class="row">
        <div class="col-md-10 col-md-offset-1">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3>Crear slider</h3>
                </div>

                <div class="panel-body">
                    {!! Form::open(['route' => 'home.store', 'method' => 'POST', 'files' => true]) !!}

                        @include('home.form')

                    {!! Form::close() !!}
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

Actual form:

<div class="form-group">
    {!! Form::label('text', 'Texto') !!}
    {!! Form::text('text', null, ['class' => 'form-control', 'placeholder' => 'Texto', 'required']) !!}
</div>
<div class="form-group">
    {!! Form::label('order', 'Orden') !!}
    {!! Form::text('order', null, ['class' => 'form-control', 'placeholder' => 'Orden', 'required']) !!}
</div>
<div class="form-group">
    {!! Form::label('Imagen ') !!}
</div>
<div class="form-group">
    @if( ! isset($home->image))
        <div class="col-sm-6">
            {!! Form::file('image', null, array('class' => 'image')) !!}
        </div>
    @else
        <div class="col-sm-6">
            <img class="thumbnail" src="/image/stores//" width="200" height="100">
            {!! Form::text('image', $home->image, array('class' => 'image hidden')) !!}
            {!! Form::file('image', null, array('class' => 'image', 'form-control')) !!}
        </div>
    @endif
</div>
<div class="form-group">
    {!! Form::submit('Guardar', ['class' => 'btn btn-primary']) !!}
</div>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire