app/Http/Controllers/PeliculaController.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(PeliculaRequest $request)
    {
        try{
            $pelicula=Pelicula::create($request->except('idGenero','idActor'));
            $pelicula->generos()->sync($request->idGenero);
            $pelicula->actores()->sync($request->idActor);
            return redirect('peliculas')->with('success','Película registrada');
        }catch(Exception $e){
            return back()->withErrors(['exception'=>$e->getMessage()])->withInput();
        }
    }
public function store ( PeliculaRequest $ request ) { try { $ pelicula = Pelicula :: create ( $ request -> except ( 'idGenero' , 'idActor' ) ) ; $ pelicula -> generos ( ) -> sync ( $ request -> idGenero ) ; $ pelicula -> actores ( ) -> sync ( $ request -> idActor ) ; return redirect ( 'peliculas' ) -> with ( 'success' , 'Película registrada') ; } catch ( Exception $ e ) { return back ( ) -> withErrors ( [ 'exception' => $ e -> getMessage ( ) ] ) -> withInput ( ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .
//if ($request->hasFile('imagen')) { //    $pelicula->imagen = $request->file('imagen')->store('public/peliculas'); //    $pelicula->save(); //}