app/Http/Controllers/ReceitasController.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(StoreRequestReceitas $request)
    {
        $fields = $request->validated();
        $receita = new Receitas();
        $receita->fill($fields);
        $receita->id_categoria = $request->id_categoria;
        $receita->id_user = Auth::user()->id;
        if ($request->hasFile('img')) {
            $photo_path = $request->file('img')->store('public/receitas');
            $receita->foto = $request->file('img')->hashName();
        }
        $receita->save();
        return redirect()->route('receitas.index');
    }
public function store ( StoreRequestReceitas $ request ) { $ fields = $ request -> validated ( ) ; $ receita = new Receitas ( ) ; $ receita -> fill ( $ fields ) ; $ receita -> id_categoria = $ request -> id_categoria ; $ receita -> id_user = Auth :: user ( ) -> id ; if ( $ request -> hasFile ( 'img' ) ) { $ photo_path = $ request -> file ( 'img' ) -> store ( 'public/receitas' ) ; $ receita -> foto = $ request -> file ( 'img' ) -> hashName ( ) ; } $ receita -> save ( ) ; return redirect ( ) -> route ( 'receitas.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .