app/Http/Controllers/FrontPostController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\RedirectResponse
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $post = new PostModel();
        $post->titulo = $request['titulo'];
        $post->descricao = $request['descricao'];
        $post->id_user = $request['id_user'];
        $file = $request->file('imagem');
        if ($file !=null){
            $newName = str_replace('.'.$file->getClientOriginalExtension() , '' , strtolower( preg_replace('/[ -]+/' , '_' , strtr(utf8_decode(trim($file->getClientOriginalName())), utf8_decode("áàãâéêíóôõúüñçÁÀÃÂÉÊÍÓÔÕÚÜÑÇ"), "aaaaeeiooouuncAAAAEEIOOOUUNC-")) )).'_'.uniqid().'.'.$file->getClientOriginalExtension();
            $file->move(public_path('posts'), $newName);
            $post->imagem = "posts/".$newName;
        }
        $post->save();
        flash('Post inserido com sucesso!')->success();
        return redirect()->route('post.index');
    }
public function store ( Request $ request ) { $ post = new PostModel ( ) ; $ post -> titulo = $ request [ 'titulo' ] ; $ post -> descricao = $ request [ 'descricao' ] ; $ post -> id_user = $ request [ 'id_user' ] ; $ file = $ request -> file ( 'imagem' ) ; if ( $ file != null ) { $ newName = str_replace ( '.' . $ file -> getClientOriginalExtension ( ) , '' , strtolower ( preg_replace ( '/[ -]+/' , '_' , strtr ( utf8_decode ( trim ( $ file -> getClientOriginalName ( ) ) ) , utf8_decode ( " áàãâéêíóôõúüñçÁÀÃÂÉÊÍÓÔÕÚÜÑÇ"), "aaaaeeiooouuncAAAAEEIOO O U U C -")) )).'_'.uniqid().'.'.$fil e - > e t C lie n tOrigi n a l Ext e n sion () ; $ file -> move ( public_path ( 'posts' ) , $ newName ) ; $ post -> imagem = " posts/ " . $ newName ; } $ post -> save ( ) ; flash ( 'Post inserido com sucesso!' ) -> success ( ) ; return redirect ( ) -> route ( 'post.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .