Class' App \ Http \ Controllers \ Image'找不到 - HomeController.php第53行 - Laravel 5.1

时间:2017-02-18 20:26:59

标签: php laravel laravel-5.1 filepath

这是我提交创建代码时遇到的错误。看起来我的public_path没有得到商店功能的尊重,因此它会寻找一个名为Image的控制器。

希望你们能帮助我找出错误。

<?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');
    }
}

我的公共路径是 - &gt;公共/图像/舍

创建功能:

@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

实际形式:

<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/{{ $home->id }}/{{ $home->icon }}" 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>

0 个答案:

没有答案