我正在尝试使用回形针库上载和显示我现在正在工作的某些博客帖子的图像。
我无法弄清楚如何使其发挥作用,这是我所做的:
我的帖子模型如下:
class Post extends Model {
public function __construct(array $attributes = []) {
$this->hasAttachedFile('image', [
'variants' => [
'medium' => [
'auto-orient' => [],
'resize' => ['dimensions' => '300x300'],
],
'thumb' => '100x100',
],
'attributes' => [
'variants' => true,
],
]);
parent::__construct($attributes);
}
protected $fillable = ['title', 'body', 'user_id', 'image_file_name'];
我的帖子迁移如下:
class CreatePostsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up() {
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users');
$table->string('title', 256);
$table->string('slug', 256);
$table->string('image_file_name')->nullable();
$table->integer('image_file_size')->nullable();
$table->string('image_content_type')->nullable();
$table->timestamp('image_updated_at')->nullable();
$table->text('body');
$table->timestamps();
});
}
我该如何在我的PostsController中对待它,它看起来像这样的atm:
public function store(StorePostRequest $request) {
Post::create([
'title' => request('title'),
'body' => request('body'),
'image_file_name' => request('image_file_name'),
'user_id' => auth()->id()
]);
return redirect('/');
}
请帮忙!谢谢