L
L
lynnikvadim2015-08-28 15:09:13
Laravel
lynnikvadim, 2015-08-28 15:09:13

Why isn't Laravel loading pictures?

Routes:

Route::get('admin/category',['uses'=>'admin\[email protected]', 'as'=>'category', 'middleware'=>'auhtgust']);
Route::post('admin/category',['uses'=>'admin\[email protected]', 'as'=>'categorystore', 'middleware'=>'auhtgust']);

My controller:
<?php namespace App\Http\Controllers\admin;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;
use App\Category;

class CatController extends Controller {

  /**
   * Display a listing of the resource.
   *
   * @return Response
   */
  public function __construct()
  {
    $this->middleware('auth');
  }


  public function index()

  {
    $Category = Category::all();
     

    return view ('admin.Category', ['Category'=>$Category]);

  }

  /**
   * Show the form for creating a new resource.
   *
   * @return Response
   */
  public function create()
  {
    //
  }

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

     
          $Category = new Category();
          $Category->name= $request->input('name');
          
          $img=Input::file('img');
          $filename=date('Y-m-d-H:i:s')."-".$img->getClientOriginalName();
          Images::make($img->getRealPath())-resize(300,200)->save('public/site/img/category/'.$filename);
          $path="public/site/img/category/";
          $Category->img='site/img/category'.$filename;
          $Category->save();
          


    Flash::success('Категория добавленна.');
    return redirect('admin/');
  }

  /**
   * Display the specified resource.
   *
   * @param  int  $id
   * @return Response
   */
  public function show($id)
  {
    //
  }

  /**
   * Show the form for editing the specified resource.
   *
   * @param  int  $id
   * @return Response
   */
  public function edit($id)
  {
    //
  }

  /**
   * Update the specified resource in storage.
   *
   * @param  int  $id
   * @return Response
   */
  public function update($id)
  {
    //
  }

  /**
   * Remove the specified resource from storage.
   *
   * @param  int  $id
   * @return Response
   */
  public function destroy($id)
  {
    //
  }

}

My view:
{!! Form::open(['route'=>'categorystore','method' => 'POST', 'files' => true]) !!}
                  <div class="form-group">
                  <label>Имя категории:</label>
                    <div class="input-group">
                      <div class="input-group-addon">
                        <i class="fa fa-user"></i>
                      </div>
                      {!! Form::text('name', null, ['class'=>'form-control pull-right' ]) !!}
                      
                    </div>                
                </div>
                <div class="form-group">
                  <label>Картинка:</label>
                    <div class="input-group">
                      <div class="input-group-addon">
                        <i class="fa fa-envelope-o"></i>
                      </div>
                      {!! Form::file('img', null, ['class'=>'form-control pull-right' ]) !!}
                      
                    </div>                
                </div>       
                {!! Form::submit('Создать',['class'=>'btn btn-block btn-success']) !!}
                {!! Form::close() !!}

My Model:
<?php namespace App;

use Illuminate\Database\Eloquent\Model;

class Category extends Model {

  protected $table = 'categories';

  /**
   * The attributes that are mass assignable.
   *
   * @var array
   */
  protected $fillable = ['name', 'img'];

  /**
   * The attributes excluded from the model's JSON form.
   *
   * @var array
   */
  protected $hidden = ['id', 'remember_token','_token',];


}

After I press the "Create" button, I see a white screen. Doesn't even show errors.
There is no record in the database and there is no picture in the folder.
What is the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2015-08-28
@alexey-m-ukolov

You have the controller in namespace , but you are calling the Images and Flash classes that are not imported anywhere .
Turn on error display and learn how to look in ./storage/logs.

V
Vyacheslav Plisko, 2015-08-28
@AmdY

Look at the server logs for the error.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question