1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Laravel Nova 画像アップロードしてみた

Posted at

環境

PHP 7.2.21
Laravel 6.3.0
Laravel Nova 2.5.0

実装

テーブル作成

php artisan make:migration create_picture_uploads_table
src/database/migrations/create_picture_uploads_table.php

    public function up()
    {
        Schema::create('picture_uploads', function (Blueprint $table) {
            $table->Increments('id');
            $table->string('picture'); //追加
            $table->timestamps();
        });
    }


モデル作成

php artisan make:model Models/PictureUpload

リソース作成

 php artisan nova:resource PictureUpload
src/app/Nova/PictureUpload
use Laravel\Nova\Fields\Image;

    public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),
            Image::make('picture')
                ->disk('public')
        ];
    }

マイグレーション実行

php artisan migrate

シンボリックリンク作成

php artisan storage:link

スクリーンショット 2019-11-29 15.37.56.png

src/storage/app/public/wF17xoqTUlF9vN4SZuz7eXIRyOHe66weuhmEbtqg.png //画像保存先

<img src="/storage/wF17xoqTUlF9vN4SZuz7eXIRyOHe66weuhmEbtqg.png"> //使用方法
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?