app/Http/Controllers/PostController.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)
    {
        $post                        = new PostModel;
        if($request->hasFile('imagen'))
        {
            $file=$request->file('imagen');
            $name=time()."_imagen".'.'.$file->getClientOriginalExtension();
            $file->move(public_path().'/imagen/',$name);
            $foto=$name;
            $current_timestamp           = date ('Y-m-d H:i:s');
            $post->clave_categoria       = $request['clave_categoria'];
            $post->clave_usuario         = null;
            $post->contenido             = $request['contenido'];
            $post->descripcion           = $request['descripcion'];
            $post->imagen                = $foto;
            $post->titulo                = $request['titulo'];
            $post->fecha_alta            = $current_timestamp;
            $post->save();
        }
        return $post;
    }
public function store ( Request $ request ) { $ post = new PostModel ; if ( $ request -> hasFile ( 'imagen' ) ) { $ file = $ request -> file ( 'imagen' ) ; $ name = time ( ) . " _imagen " . '.' . $ file -> getClientOriginalExtension ( ) ; $ file -> move ( public_path ( ) . '/imagen/' , $ name ) ; $ foto = $ name ; $ current_timestamp = date ( 'Y-m-d H:i:s' ) ; $ post -> clave_categoria = $ request [ 'clave_categoria' ] ; $ post -> clave_usuario = null ; $ post -> contenido = $ request [ 'contenido' ] ; $ post -> descripcion = $ request [ 'descripcion' ] ; $ post -> imagen = $ foto ; $ post -> titulo = $ request [ 'titulo' ] ; $ post -> fecha_alta = $ current_timestamp ; $ post -> save ( ) ; } return $ post ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
//$file->move(public_path().'/img/',$name); //$file->move(public_path().'/imagen/',$name);