app/Http/Controllers/Api/MovieController.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)
    {
      $validated = $request->validate([
        'name' => 'required|max:255',
        'description' => 'required',
        'duration' => 'required',
        'cover' => 'required|file',
        'launch' => 'required|date'
      ]);
      $movie = new Movie;
      $movie->name = $request->name;
      $movie->description = $request->description;
      $movie->duration = $request->duration;
      $movie->trailer = $request->trailer;
      $movie->launch = $request->launch;
      if($request->hasFile('cover')) {
        $img = Image::make($request->file('cover'))->fit(260,340)->encode('png');
        $movie->cover = Str::random(40).'-cover.png';
        $store = Storage::disk('public')->put($movie->cover, $img);
      }
      $movie->save();
      $movie->categories()->attach(explode(',', $request->storeCategories));
      return response()->json($movie);
    }
public function store ( Request $ request ) { $ validated = $ request -> validate ( [ 'name' => 'required|max:255' , 'description' => 'required' , 'duration' => 'required' , 'cover' => 'required|file' , 'launch' => 'required|date' ] ) ; $ movie = new Movie ; $ movie -> name = $ request -> name ; $ movie -> description = $ request -> description ; $ movie -> duration = $ request -> duration ; $ movie -> trailer = $ request -> trailer ; $ movie -> launch = $ request -> launch ; if ( $ request -> hasFile ( 'cover' ) ) { $ img = Image :: make ( $ request -> file ( 'cover' ) ) -> fit ( 260 , 340 ) -> encode ( 'png' ) ; $ movie -> cover = Str :: random ( 40 ) . '-cover.png' ; $ store = Storage :: disk ( 'public' ) -> put ( $ movie -> cover , $ img ) ; } $ movie -> save ( ) ; $ movie -> categories ( ) -> attach ( explode ( ',' , $ request -> storeCategories ) ) ; return response ( ) -> json ( $ movie ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
//load images