app/Http/Controllers/VinhosController.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(StoreVinhosRequest $request)
    {
        $fields = $request->validated();
        $vinho = new Vinhos();
        $vinho_foto = new Vinhosimg();
        $vinho->fill($fields);
        $vinho->id_categoria = $request->id_categoria;
        if ($request->hasFile('img')) {
            $photo_path = $request->file('img')->store('public/vinhos');
            $vinho->img = $request->file('img')->hashName();
            $vinho_foto->img = $request->file('img')->hashName();
        }
        $vinho->save();
        $vinho_foto->id_vinho = $vinho->id;
        $vinho_foto->save();
        return redirect()->route('vinhos.index')->with('success', 'Vinho adicionado com sucesso', compact('vinho'));
    }
public function store ( StoreVinhosRequest $ request ) { $ fields = $ request -> validated ( ) ; $ vinho = new Vinhos ( ) ; $ vinho_foto = new Vinhosimg ( ) ; $ vinho -> fill ( $ fields ) ; $ vinho -> id_categoria = $ request -> id_categoria ; if ( $ request -> hasFile ( 'img' ) ) { $ photo_path = $ request -> file ( 'img' ) -> store ( 'public/vinhos' ) ; $ vinho -> img = $ request -> file ( 'img' ) -> hashName ( ) ; $ vinho_foto -> img = $ request -> file ( 'img' ) -> hashName ( ) ; } $ vinho -> save ( ) ; $ vinho_foto -> id_vinho = $ vinho -> id ; $ vinho_foto -> save ( ) ; return redirect ( ) -> route ( 'vinhos.index' ) -> with ( 'success' , 'Vinho adicionado com sucesso' , compact ( 'vinho' ) ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .