Problems with form using PHP with Laravel

0

Next I developed a site using laravel I am programming a form but it has no action I have already finished it does not work when I click send, it does not only do reload on the page and does not appear even the errors even if I fill or leave empty it does not work someone there can help me follow my code it will be sent to my g -mail but use own domain instead of using [email protected] the domain is [email protected] follow the codes:

PHP:

<div class="row">
                   @if (count($errors) > 0)
                        <div class="alert alert-danger">
                            <ul>
                                @foreach ($errors->all() as $error)
                                    <li>{{ $error }}</li>
                                @endforeach
                            </ul>
                        </div>
                    @endif

                    @if (session('message'))
                        <div class="alert alert-success">
                            {!! session('message')  !!}
                        </div>
                    @endif

                    {!! Form::open(array('action' => 'FormController@postContato', 'role' => 'form', 'class'=>'form')) !!}
                    <div class="form-group">
                        <div class="row">
                            <div class="col-md-6">
                                {!! Form::text('nome', null, array('placeholder'=>'Nome')) !!}
                                {!! Form::text('email', null, array('placeholder'=>'E-mail')) !!}
                                {!! Form::text('telefone', null, array('placeholder'=>'Telefone')) !!}
                            </div>
                            <div class="col-md-6">
                                {!! Form::textarea('mensagem', null, array('placeholder'=>'Mensagem', 'rows'=>'5')) !!}
                                {!! Form::submit('Enviar', array('class' => 'btn btn-success'), array('id' => 'btn_submit')) !!}
                            </div>

                        </div>
                    </div>
                    {!! Form::close() !!}
            </div>  

Route:

Route::post('/', 'FormController@postContato');

Controller:

application/x-httpd-php FormController.php ( PHP script text )

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Validator;
use Mail;
use App\Http\Requests;

class FormController extends Controller
{
    public function index() {
        return view('/');
    }


    public function postContato(Request $request) {
        $rules = array( 'nome' => 'required', 'email' => 'required|email', 'telefone' => 'required', 'mensagem' => 'required' );
        $errors = [
            'required'    => 'O campo :attribute é obrigatório.',
            'email'    => 'Digite um email válido.',
        ];
        $validation = Validator::make($request->all(), $rules, $errors);
        $data = array();
        $data['nome'] = $request->input("nome");
        $data['email'] = $request->input("email");
        $data['telefone'] = $request->input("telefone");
        $data['mensagem'] = $request->input("mensagem");

        if($validation->passes()) {
            Mail::send('emails.contato', $data, function($message) use($request){
                $message->from($request->input("email"), $request->input("nome"));
                $message->to('[email protected]') ->subject('contato do site');
                $message->bcc('[email protected]') ->subject('Contato do site');

            });
            return redirect('#contato')->with('message', 'Mensagem enviada com sucesso!');
        }
        return redirect('#contato')->withErrors($validation);
    }
}

Mail.php

<?php

return [
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'smtp.agenciafront.com.br'),
    'port' => env('MAIL_PORT', 587),
    'from' => ['address' => null, 'name' => null],
    'encryption' => env('MAIL_ENCRYPTION', 'ssl'),
    'username' => env('[email protected]'), 
    'password' => env('xxxxxx123'),
    'sendmail' => '/usr/sbin/sendmail -bs',

];

.ENV:

APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:CBnXZVj0+0xnFYhUnrOWQRKvmobN0qmB8fIFq/3pnFs=
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.agenciafront.com.br
MAIL_PORT=587
[email protected] 
MAIL_PASSWORD=xxxxx-123
MAIL_ENCRYPTION=ssl

OBS: Access the site in the link placed in the question there you can see that form has no action at all. version of Laravel 5.2

    
asked by anonymous 18.05.2017 / 20:30

1 answer

1

You're sending the direct action pro controller. You must use ROUTE NAME in the FORM action. and modify the database data (DB_DATABASE = homestead, DB_USERNAME = homestead, DB_PASSWORD = secret) to your data.

    
15.05.2018 / 18:33