app/Http/Controllers/Admin/BannerController.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();
        if($request->hasFile('image')) {
            $image = $request->file('image');
            $filename = str_random(28) . '.jpg';
            $path = 'public/banners/' . $filename;
            $file = Image::make($image->getRealPath())->encode('jpg',75);
            Storage::put($path, (string) $file);
            $data['image'] = Storage::url($path);
        }
        $this->banner->create($data);
        return response()->json([
            'status' => 'data created'
        ], 201);
    }
public function store ( Request $ request ) { $ data = $ request -> all ( ) ; if ( $ request -> hasFile ( 'image' ) ) { $ image = $ request -> file ( 'image' ) ; $ filename = str_random ( 28 ) . '.jpg' ; $ path = 'public/banners/' . $ filename ; $ file = Image :: make ( $ image -> getRealPath ( ) ) -> encode ( 'jpg' , 75 ) ; Storage :: put ( $ path , ( string ) $ file ) ; $ data [ 'image' ] = Storage :: url ( $ path ) ; } $ this -> banner -> create ( $ data ) ; return response ( ) -> json ( [ 'status' => 'data created' ] , 201 ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .