我对使用laravel上传图片有疑问。我在我的刀片文件中完成了上传按钮以上传图片。 我按照网站上的所有步骤操作: http://image.intervention.io/getting_started/installation#laravel 我在google上搜索了2个小时的答案,很多人遇到了和我一样的问题...... 所以基本上,在我的控制器中,我能够通过执行dd()的请求捕获我的图像,但页面顶部有一个问题。使用Image不起作用,当然也" Image :: make,resize等...我尝试不同的设置,但它们都没有工作....
有人知道如何继续吗?在这里我的档案:
刀片文件:
<div class="col-md-8">
<form method="POST" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="content">
<h1>Create a new artist or band:</h1>
<div class="form-group">
<div class="col-lg-6">
<input class="form-control" type="text" name="artistName" placeholder="Artist Name" >
</div>
</div>
<div class="form-group">
<div class="col-lg-6">
<input class="form-control" type="text" name="musicGenre" placeholder="Music genre" >
</div>
</div>
<div class="form-group">
<div class="col-lg-6">
<input type="file" name="picture">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</div>
</div>
<div class="form-group">
<div class="col-lg-6">
<a class="btn btn-primary" href="{{route('show-artist') }}" > Back </a>
<button class="btn btn-success" type="submit"> {{ 'Submit' }}</button>
</div>
</div>
</div>
@if (count($errors))
<div class="form-group">
<div class="alert alert-danger">
<ul>
@foreach($errors->all() as $error)
<li> {{ $error }}</li>
@endforeach
</ul>
</div>
</div>
@endif
</form>
</div>
这是我的控制器:
namespace projetconcert \ Http \ Controllers;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use projetconcert\Http\Requests\ArtistRequest;
use projetconcert\Artist;
use Intervention\Image\Image as Image;
/*use Image;*/
class ArtistController extends Controller
{
/**
* Display a listing of the differents artists & bands.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$data = Artist::all();
return view('artists.artist',
[
'artists'=>$data,
]
);
}
/**
* @Get("/create-artist")
*/
public function getCreateArtist()
{
return view ('artists.create.edit');
}
/**
* @Post("/create-artist")
*
* @param Request $request
* @param ArtistRequest $artistRequest
*
* @return \Illuminate\Http\RedirectResponse
*/
public function postCreateArtist(Request $request, ArtistRequest $artistRequest)
{
$artistRequest-> validated($request);
try
{
$name = $request->input('artistName');
$musicgenre = $request->input('musicGenre');
$picture = $request->file('picture');
$filename = time(). '.' . $picture->getClientOriginalExtension();
Image::make($picture)->resize(300, 300)->save(public_path('../images/uploads/pictures/' . $filename));
$artist = new Artist();
$artist->artist_name = $name;
$artist->music_genre = $musicgenre;
$artist->picture = $filename;
$artist->save();
flash()->success('Your artist or band have been created !');
}
catch (\Exception $e)
{
flash()->error("Your artist or band haven't been created !");
return redirect()->back();
}
return redirect()->route('show-artist');
}
}
提前致谢!!
答案 0 :(得分:0)
您是否完成了所有这些步骤
安装图片干预
作曲家需要干预/图像
在您的config / app.php文件中,添加以下内容
在$ providers数组中添加服务提供者
Intervention\Image\ImageServiceProvider::class
并将此包的外观添加到$ aliases数组
'图片'=&gt;干预\图片\外墙\图片::类
现在在你的控制器中,你可以写
使用Image;