app/Http/Controllers/Admin/CollectionController.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)
    {
        $data = $request->all();
        $count = $this->collection->where('volume', $data['volume'])->count();
        if($count < 9) {
            if($request->hasFile('image')) {
                $image = $request->file('image');
                $filename = str_random(28) . '.jpg';
                $path = 'public/collections/' . $filename;
                $file = Image::make($image->getRealPath())->encode('jpg',75);
                Storage::put($path, (string) $file);
                $data['path'] = Storage::url($path);
                $data['size'] = $file->filesize();
            }
            $this->collection->create($data);
            return response()->json([
                'status' => 'data created'
            ], 201);
        } else {
            return response()->json([
                'message' => 'sudah melewati kuota'
            ], 400);
        }
    }
public function store ( Request $ request ) { $ data = $ request -> all ( ) ; $ count = $ this -> collection -> where ( 'volume' , $ data [ 'volume' ] ) -> count ( ) ; if ( $ count < 9 ) { if ( $ request -> hasFile ( 'image' ) ) { $ image = $ request -> file ( 'image' ) ; $ filename = str_random ( 28 ) . '.jpg' ; $ path = 'public/collections/' . $ filename ; $ file = Image :: make ( $ image -> getRealPath ( ) ) -> encode ( 'jpg' , 75 ) ; Storage :: put ( $ path , ( string ) $ file ) ; $ data [ 'path' ] = Storage :: url ( $ path ) ; $ data [ 'size' ] = $ file -> filesize ( ) ; } $ this -> collection -> create ( $ data ) ; return response ( ) -> json ( [ 'status' => 'data created' ] , 201 ) ; } else { return response ( ) -> json ( [ 'message' => 'sudah melewati kuota' ] , 400 ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .