-1

enter image description here

this shows the error when i tried migrating it.

So I am trying to input my data from a register form I make myself.

I've tried changing the my.cnf file to set the max_allowed_packet to 16MB or 32MB but that still didn't work.

This is my RegisterController.php

namespace App\Http\Controllers\Auth;

use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;

class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/

use RegistersUsers;

/**
 * Where to redirect users after registration.
 *
 * @var string
 */
protected $redirectTo = '/login';

/**
 * Create a new controller instance.
 *
 * @return void
 */
public function __construct()
{
    $this->middleware('guest');
}

/**
 * Get a validator for an incoming registration request.
 *
 * @param  array  $data
 * @return \Illuminate\Contracts\Validation\Validator
 */
protected function validator(array $data)
{
    return Validator::make($data, [
        'name' => 'required|string|max:255',
        'email' => 'required|string|email|max:255|unique:users',
        'password' => 'required|string|min:6|confirmed',
    ]);
}

/**
 * Create a new user instance after a valid registration.
 *
 * @param  array  $data
 * @return \App\User
 */
protected function create(array $data)
{
    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'address' =>$data['address'],
        'password' => bcrypt($data['password']),
    ]);
}
}

This is my register.blade.php

@extends('layouts.app')

@section('content')
<div class="container">
<div class="row">
    <div class="col-md-8 col-md-offset-2">
        <div class="panel panel-default">
            <div class="panel-heading">Register</div>

            <div class="panel-body">
                <form class="form-horizontal" method="POST" action="{{ route('register') }}">
                    {{ csrf_field() }}

                    <div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
                        <label for="name" class="col-md-4 control-label">Name</label>

                        <div class="col-md-6">
                            <input id="name" type="text" class="form-control" name="name" value="{{ old('name') }}" required autofocus>

                            @if ($errors->has('name'))
                                <span class="help-block">
                                    <strong>{{ $errors->first('name') }}</strong>
                                </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
                        <label for="email" class="col-md-4 control-label">E-Mail Address</label>

                        <div class="col-md-6">
                            <input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required>

                            @if ($errors->has('email'))
                                <span class="help-block">
                                    <strong>{{ $errors->first('email') }}</strong>
                                </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
                        <label for="password" class="col-md-4 control-label">Password</label>

                        <div class="col-md-6">
                            <input id="password" type="password" class="form-control" name="password" required>

                            @if ($errors->has('password'))
                                <span class="help-block">
                                    <strong>{{ $errors->first('password') }}</strong>
                                </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>

                        <div class="col-md-6">
                            <input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-md-6 col-md-offset-4">
                            <button type="submit" class="btn btn-primary">
                                Register
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
</div>
@endsection

And this is my web.php

<?php


Route::resource('home', 'CustomerController');

Route::get('/login', function () {
return view('login');
});

Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');

Route::get('/', function (){
return view('home');
});

Route::get('/form', [
'uses' => 'ContactMessageController@create'
]);

Route::post('/form', [
'uses' => 'ContactMessageController@store',
'as' => 'form.store'
]);

Route::post('sendemail', ['as' => 'sendemail', 'uses' => 'ContactMessageController@store']);

So when I click on the submit button, it'll show the error:

SQLSTATE[HY000] [2006] MySQL server has gone away

Please help

this is my .env file

    APP_NAME=Laravel
    APP_ENV=local
    APP_KEY=base64:Fdkk8GmjtoJ98UdC44AE7cQ0MWvWKZen0WIssiR1/LA=
    APP_DEBUG=true
    APP_LOG_LEVEL=debug
    APP_URL=http://localhost

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=85
    DB_DATABASE=Internship
    DB_USERNAME=root
    DB_PASSWORD=

    BROADCAST_DRIVER=log
    CACHE_DRIVER=file
    SESSION_DRIVER=file
    SESSION_LIFETIME=120
    QUEUE_DRIVER=sync

    REDIS_HOST=127.0.0.1
    REDIS_PASSWORD=null
    REDIS_PORT=6379

    MAIL_DRIVER=log
    MAIL_HOST=smtp.mailtrap.io
    MAIL_PORT=2525
    MAIL_USERNAME=null
    MAIL_PASSWORD=null
    MAIL_ENCRYPTION=null

    PUSHER_APP_ID=
    PUSHER_APP_KEY=
    PUSHER_APP_SECRET=
    PUSHER_APP_CLUSTER=mt1
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
calvinerico
  • 121
  • 1
  • 2
  • 6
  • Can you please post your .env file? Also, what platform are you running on? My gut is telling me that this problem has nothing to do with your Laravel setup. – Michael Miller Feb 13 '19 at 10:11
  • i've posted is @MichaelMiller – calvinerico Feb 14 '19 at 02:56
  • Can you post the last 50 lines of you MySQL error log file (normally located at /var/log/mysql/ (this is a guess, as I don't know what Linux distro you're running), and assuming you have the proper tools to run `sudo service mysql status` (again, a guess because I don't know what Linux distro you're running), but I'm curious to see the output of that command as well. – Michael Miller Feb 14 '19 at 08:11

2 Answers2

2

This is not a Laravel issue, but a general MySQL Issue. Maybe the server is not running. Are you sure you're running MySQL in the background?

Check this link: MySQL Gone Away

Do the following checks in your system:

  1. The Database Engine is running
  2. You have created your database
  3. You have created an user and granted permissions to the database
  4. You have setup the user and the database in your Laravel's .env file.

After this, try to run the migrations command again, which is:

php artisan migrate

As explained Here

Credits to @Andrés Smerkin mysql server has gone away error during installing migration (laravel)

Jasper Helmich
  • 668
  • 4
  • 21
-1

Hello i had the same issue but i will ask you to check if the user of your database had all priveleges to create, update and delete. so for exmple in my case i went to phpmyadmin i was searching fro the user which i use in my .env file for example login :root passwod : root i also think you're missing somthing with the port mysql default port are 3306 so the user in my case is root i went to phpmyadmin to the home then in the user acount server privileges make sure the user had the same config root localhost YES ALL PRIVILEGES YES

CodingStudent
  • 53
  • 1
  • 1
  • 9