我正在关注DevsBrasil' Laravel tutorial,尝试裁剪用户图片。
并提供此错误'方法文件不存在。 (查看:C:\ xampp \ htdocs \ event \ app \ views \ dashboard \ users \ edit.blade.php)'
控制器:
public function editUsers($userID) {
$user = Sentry::findUserById($userID);
$data = array();
$data['image'] = Session::get('img');
$data['modal'] = (Session::get('modal') == null ? 'false' : 'true');
$group_p = $user->getGroups();
$groups_p = [];
foreach (Sentry::findAllGroups() as $group) {
$groups_p [$group->id] = $group->name;
}
return View::make('dashboard.users.edit')
->with('user',$user)
->with('group_p',$group_p)
->with('groups_p',$groups_p)
->with('data',$data);
}
public function updateUsers($userID) {
$user = Sentry::findUserById($userID);
return View::make('dashboard.users.edit')
->with('user',$user);
}
public function UploadImg($userID)
{
if (Input::hasFile('image')) {
$user = Sentry::findUserById($userID);
$image_name = $image->getClientOriginalName();
$image = Input::file('image');
$filename = $user->username . '.' . $image->getClientOriginalExtension();
$path = public_path('img/users/' . $filename);
$int_image = Image::make($image->getRealPath());
$int_image->resize(568,null, function($constraint){
$constraint->aspectRatio();
});
$int_image->save($path);
$user->image = 'img/users/'.$filename;
Session::put('modal','ture');
}else{
}
return Redirect::back();
}
public function CropImg()
{
return Redirect::back();
}
路线
Route::get('/admin.dashboard/users', [
'as' => 'users_get',
'uses' => 'AuthController@getUsers'
]);
Route::get('/admin.dashboard/users/edit/{userID}', [
'as' => 'edit_user_form_get',
'uses' => 'AuthController@editUsers'
]);
Route::put('/', [
'as' => 'update_user_form_get',
'uses' => 'AuthController@updateUsers'
]);
Route::post('/admin.dashboard/users/update-user-image/{userID}', [
'as' => 'update_user_image_post',
'uses' => 'AuthController@UploadImg'
]);
Route::post('/admin.dashboard/users/crop-user-image', [
'as' => 'crop_user_image_post',
'uses' => 'AuthController@CropImg'
]);
编辑视图: 这两种方法在控制器中 - 上面 -
@extends('dashboard.mainlayout')
@section('title')
Edit {{$user->first_name}} Acc
@stop
@section('scripts_header')
@stop
@section('scripts_footer')
<script>
var modal;
if ($('#modal').val() == 'ture' ) {
modal = true;
}else{
modal = false;
}
$(document).ready(function(){
$('#crop').Jcrop({
aspectRatio: 1,
onSelect: atualizaCoordenadas
});
$('#img_modal').modal({show: modal});
});
function atualizaCoordenadas(c){
$('#x').val(c.x);
$('#y').val(c.y);
$('#w').val(c.w);
$('#h').val(c.h);
}
function checkCoords(){
if (parseInt($('#w').val())) return true;
alert('Error');
return false;
}
</script>
@stop
@section('content')
<div class="row">
<div class="col-md-12">
<div class="bootbox modal fade in" id="img_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: block;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Crop Image</h4>
</div>
<div class="modal-body">
{{Form::open(array('route' => 'crop_user_image_post', 'onsubmit' => 'return checkCoords' ,'class'=>'form-horizontal'))}}
{{HTML::image($data['image'], '' , ['id' => 'crop'] )}}
<input type="hidden" id="src" name="src" value="{{ $data['image'] }}" >
<input type="hidden" id="x" name="x" />
<input type="hidden" id="y" name="y" />
<input type="hidden" id="w" name="w" />
<input type="hidden" id="h" name="h" />
</div>
<div class="modal-footer">
<button data-bb-handler="Done" type="button" class="btn btn-success">Success!</button>
</div>
{{ Form::close() }}
</div>
</div>
{{Form::open(array('route' => 'update_user_image_post', 'method' => 'post','files'=>'true','class'=>'form-horizontal') , $user->id)}}
{{ HTML::image($user->img, $user->username, array('class' => 'img-circle' )) }}
{{HTML::file('image')}}
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Upload Image <i class="fa fa-check"></i></button>
</div>
</div>
{{ Form::close() }}
</div>
</div>
</div>
<!-- // Tab content END -->
@stop
哪里出错? 我该怎么做?
答案 0 :(得分:1)
可能在抱怨
{{HTML::file('image')}}
因为HTML Builder类中没有文件方法。
答案 1 :(得分:1)
{{HTML::file('image')}}
我不相信file
别名上的任何HTML
方法。该类是HTML
facade(Illuminate\Support\Facades\HTML
)的别名,它只是进入类Illuminate\Html\HtmlBuilder
的IoC容器的快捷方式。查看该课程,我没有提及file
方法。