app/Http/Controllers/Dashboard/ProductController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
          $product = new Product();
          $product->name = $request->input('name');
          $product->description = $request->input('description');
          $product->price = $request->input('price');
          $product->category_id = $request->input('category_id');
            if ($request->input('recommend') == 'on') {
                $product->recommend_flag = true;
            } else {
                $product->recommend_flag = false;
            }
          if ($request->file('image') !== null) {
              $image = $request->file('image')->store('download/products');
              $card_img = Image::make($request->file('image'));
              $card_img->resize(300, null, function ($constraint) {$constraint->aspectRatio();});
              $height = $card_img->height() / 2;
              $width = $card_img->width() / 2;
              $card_img->text('sample', $width, $height, function($font) {
                $font->file(public_path('fonts/SawarabiGothic-Regular.ttf'));
                $font->size(30);
                $font->align('center');
                $font->color('#ffffff');
              });
              $card_img->save(storage_path('app/public/products/'.basename($image)));
              $product->image = basename($image);
          } else {
              $product->image = '';
          }
        if ($request->input('carriage') == 'on') {
            $product->carriage_flag = true;
        } else {
            $product->carriage_flag = false;
        }
        $product->save();
          return redirect()->route('dashboard.products.index');
    }
public function store ( Request $ request ) { $ product = new Product ( ) ; $ product -> name = $ request -> input ( 'name' ) ; $ product -> description = $ request -> input ( 'description' ) ; $ product -> price = $ request -> input ( 'price' ) ; $ product -> category_id = $ request -> input ( 'category_id' ) ; if ( $ request -> input ( 'recommend' ) == 'on' ) { $ product -> recommend_flag = true ; } else { $ product -> recommend_flag = false ; } if ( $ request -> file ( 'image' ) !== null ) { $ image = $ request -> file ( 'image' ) -> store ( 'download/products' ) ; $ card_img = Image :: make ( $ request -> file ( 'image' ) ) ; $ card_img -> resize ( 300 , null , function ( $ constraint ) { $ constraint -> aspectRatio ( ) ; } ) ; $ height = $ card_img -> height ( ) / 2 ; $ width = $ card_img -> width ( ) / 2 ; $ card_img -> text ( 'sample' , $ width , $ height , function ( $ font ) { $ font -> file ( public_path ( 'fonts/SawarabiGothic-Regular.ttf' ) ) ; $ font -> size ( 30 ) ; $ font -> align ( 'center' ) ; $ font -> color ( '#ffffff' ) ; } ) ; $ card_img -> save ( storage_path ( 'app/public/products/' . basename ( $ image ) ) ) ; $ product -> image = basename ( $ image ) ; } else { $ product -> image = '' ; } if ( $ request -> input ( 'carriage' ) == 'on' ) { $ product -> carriage_flag = true ; } else { $ product -> carriage_flag = false ; } $ product -> save ( ) ; return redirect ( ) -> route ( 'dashboard.products.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// 生画像 // サンプル画像の生成