Answer the question
In order to leave comments, you need to log in
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']);
<?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)
{
//
}
}
{!! 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() !!}
<?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',];
}
Answer the question
In order to leave comments, you need to log in
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
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question