Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

basosneo's avatar

SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'hola' for column 'tel' at row 1 (SQL: insert into `proveedores` (`name`, `last_name`, `email`, `user`, `active`, `address`, `tel`, `updated_at`, `created_at`) values (hola, hola, [email protected]

my if count errors donst work, why?

 @extends('admin.template')

 @section('content')

<div class="container text-center">
    <div class="page-header">
        <h1>
            <i class="fa fa-shopping-cart"></i>
            PROVEEDORES <small>[Agregar proveedores]</small>
        </h1>
    </div>

    <div class="row">
        <div class="col-md-offset-3 col-md-6">
            
            <div class="page">
                
                @if (count($errors) > 0)
                    @include('admin.partials.errors')
                @endif
                
                {!! Form::open(['route'=>'admin.proveedores.store']) !!}
                
                    <div class="form-group">
                        <label for="name">Nombre:</label>
                        
                        {!! 
                            Form::text(
                                'name', 
                                null, 
                                array(
                                    'class'=>'form-control',
                                    'placeholder' => 'Ingresa el nombre...',
                                    'autofocus' => 'autofocus',
                                    'required' => 'required'
                                )
                            ) 
                        !!}
                    </div>
                    
                    <div class="form-group">
                        <label for="last_name">Apellidos:</label>
                        
                        {!! 
                            Form::text(
                                'last_name', 
                                null, 
                                array(
                                    'class'=>'form-control',
                                    'placeholder' => 'Ingresa los apellidos...',
                                    'required' => 'required'
                                )
                            ) 
                        !!}
                    </div>
                    
                    <div class="form-group">
                        <label for="email">Correo:</label>
                        
                        {!! 
                            Form::text(
                                'email', 
                                null, 
                                array(
                                    'class'=>'form-control',
                                    'placeholder' => 'Ingresa el correo...',
                                    'required' => 'required'
                                )
                            ) 
                        !!}
                    </div>

                     <div class="form-group">
                        <label for="email">Teléfono:</label>
                        
                        {!! 
                            Form::tel(
                                'tel', 
                                null, 
                                array(
                                    'class'=>'form-control',
                                    'placeholder' => 'Ingresa el numero de teléfono...',
                                    'required' => 'required'
                                )
                            ) 
                        !!}
                    </div>
                    
                     <div class="form-group">
                        <label for="user">Area de trabajo:</label>
                        
                        {!! 
                            Form::text(
                                'user', 
                                null, 
                                array(
                                    'class'=>'form-control',
                                    'placeholder' => 'Ingresa el nombre de usuario...',
                                    'required' => 'required'
                                )
                            ) 
                        !!}
                    </div>

                     <div class="form-group">
                        <label for="address">Dirección:</label>
                        
                        {!! 
                            Form::textarea(
                                'address', 
                                null, 
                                array(
                                    'class'=>'form-control',
                                    'required' => 'required'
                                )
                            ) 
                        !!}
                    </div>

                    <div class="form-group">
                        <label for="active">Active:</label>
                        
                        {!! Form::checkbox('active', null, true) !!}
                    </div>
                    
                    <div class="form-group">
                        {!! Form::submit('Guardar', array('class'=>'btn btn-primary')) !!}
                        <a href="{{ route('admin.category.index') }}" class="btn btn-warning">Cancelar</a>
                    </div>
                
                {!! Form::close() !!}
                
            </div>
            
        </div>
        </div>
    

   </div>

   @stop
0 likes
65 replies
Snapey's avatar

You submitted 'hola' for something that should be a number.

If you don't catch this in validation then it will be passed to the database and fail because the database is looking for an integer

by the way, its a bad idea to use integer for a phone number because people put spaces, commas, + etc

basosneo's avatar

hey @snapey!

yes, I understand this, what I do not understand is because my count eerror I did not loop a wing instead of the page did?

What is your idea for the telephone numbers and how would be the only way there were numbers there?

Snapey's avatar

my count eerror I did not loop a wing instead of the page did?

Sorry, I don't understand

If you only want numbers then you need to set the correct validation rule

Please check the documentation for the available rules.

basosneo's avatar

What I mean is that I cause the error on purpose to check that my 'count error' worked, but it did not work. What he did was redirect me and the page if he showed me the error

   @if (count($errors) > 0)
                @include('admin.partials.errors')
            @endif
Snapey's avatar

Because you did not break any validation rule.

What rules do you have?

basosneo's avatar

Well until now I had put it like this in all my forms and it had worked .. how do I add a new rule then? Where are they located?

basosneo's avatar

my rules of saveproveedoresrequest

    public function rules()
     {
    return [
        'name'      => 'required|max:100',
        'last_name' => 'required|max:100',
        'email'     => 'required|email|unique:users',
        'user'      => 'required|unique:users|min:4|max:20',
        'tel'  => 'required|max:12',
        'address'  => 'required|max:100',
        
      ];
     }
Snapey's avatar

ok so tel can be any string up to 12 characters. not what you want? choose an extra rule.

basosneo's avatar

What I need is that only there they can put phone numbers, without letters or anything else

Snapey's avatar

Look, I suggest you look at the rules, but you cannot do that, so I have to give you the answer?

'tel' => 'required|max:12|integer',

Send me a spec and a bunch of money and I'll write the application for you.

basosneo's avatar

Thank you friend @snapey, I really would like to pay you to show me but I have not yet charged anything in my life, the truth is that some day you return the favor (who knows), but now I can not because I am very new ... now I have another thousand Questions more and not reading the documentation a thousand times I can understand the errors ...

basosneo's avatar

@snapey Add what you told me and now do not let me create any provider I get the following error

  QueryException in Connection.php line 647: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'jackfer.name' doesn't exist (SQL: select count(*) as aggregate from `name` where `name` = hola

Try to make dd and erase everything as it was before, but the error does not go away

Snapey's avatar

Read the error

Compare it to what you are doing

Look for error in your code

basosneo's avatar

Then I do not understand, because before it was working and not now

Snapey's avatar

OK. in this question you have a problem writing a string into the 'tel' field.

This problem is solved now?

You don't show any code for writing to the database in this topic.

basosneo's avatar

I Delete the entire controller and do it again; For a few moments I worked, then started to create the part of the update and it was there where I gave the error again, I've removed everything to see where the problem is, but now nothing works,

      <?php

    namespace App\Http\Controllers\Admin;

    use Illuminate\Http\Request;
   use App\Http\Requests;
   use App\Http\Requests\SaveProveedoresRequest;
   use App\Http\Controllers\Controller;
    use App\Proveedores;

  class ProveedoresController extends Controller
  {
   public function index()
    {
    $proveedores = Proveedores::orderBy('name')->paginate(5);
   // dd($proveedores);
        return view('admin.proveedores.index', compact('proveedores'));
     }

       public function create()
   {
    return view('admin.proveedores.create');
    }

    public function store(SaveProveedoresRequest $request)
      {
        //return $request->all();
       $data = [
       'name'          => $request->get('name'),
       'last_name'     => $request->get('last_name'),
       'email'         => $request->get('email'),
       'user'          => $request->get('user'),
       'active'        => $request->has('active') ? 1 : 0,
       'address'       => $request->get('address'),
       'tel'       => $request->get('tel'),
       ];
    
    $proveedores = Proveedores::create($data);

    $message = $proveedores ? 'Nuevo proveedor agregado correctamente!' : 'El proveedor NO pudo agregarse!';
    
     return redirect()->route('admin.proveedores.index')->with('message', $message);
        
    }
    

       public function show(Proveedores $proveedores)
     {
    return $proveedores;
    }


  public function edit(Proveedores $proveedores)
      {
    return view('admin.proveedores.edit', compact('proveedores'));
      }



      public function update(Request $request, Proveedores $proveedores)
     {
    $this->validate($request, [
        'name'      => 'required|max:100',
        'last_name' => 'required|max:100',
        'email'     => 'required|email',
        'user'      => 'required|min:4|max:20',
        'address'   => 'required|max:100',
        'tel'       => 'required|min:4|max:20'
        ]);
    
    $proveedores->name = $request->get('name');
    $proveedores->last_name = $request->get('last_name');
    $proveedores->email = $request->get('email');
    $proveedores->user = $request->get('user');
    $proveedores->type = $request->get('type');
    $proveedores->address = $request->get('address');
    $proveedores->active = $request->has('active') ? 1 : 0;
    if($request->get('password') != "") $proveedores->password = $request->get('password');
    
     $updated = $proveedores->save();
    
    $message = $updated ? 'Proveedor actualizado correctamente!' : 'El Proveedor NO pudo actualizarse!';
    
    return redirect()->route('admin.proveedores.index')->with('message', $message);
     }
     }

saveproveedoresrequests

    public function authorize()
{
    return true;
}

/**
 * Get the validation rules that apply to the request.
 *
 * @return array
 */
public function rules()
{
    return [
        'name'      => 'required|max:100|unique:name',
        'last_name' => 'required|max:100',
        'email'     => 'required|email',
        'user'      => 'required|min:4|max:20',
        'tel'       => 'required|max:30000000|integer',
        'address'   => 'required|max:100',
        
       ];
    }

model

  <?php

 namespace App;

 use Illuminate\Database\Eloquent\Model;

   class Proveedores extends Model
  {
    /**
    * The database table used by the model.
   *
     * @var string
    */
    protected $table = 'proveedores';
    /**
    * The attributes that are mass assignable.
    *
    * @var array
   */
   protected $fillable = ['name', 'email', 'tel', 'last_name', 'user', 'active', 'address'];
   }

migrations

   <?php

  use Illuminate\Support\Facades\Schema;
 use Illuminate\Database\Schema\Blueprint;
 use Illuminate\Database\Migrations\Migration;

class CreateProveedoresTable extends Migration
 {
   /**
   * Run the migrations.
    *
   * @return void
    */
   public function up()
    {
    Schema::create('proveedores', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name', 100);
        $table->string('last_name', 100);
        $table->string('email');
        $table->string('user', 50);
        $table->boolean('active');
        $table->text('address');
        $table->Integer('tel');
        $table->timestamps();
    });
    }

     /**
    * Reverse the migrations.
     *
    * @return void
      */
     public function down()
    {
    Schema::dropIfExists('proveedores');
     }
      }

web.php

    Route::resource('proveedores', 'ProveedoresController');

 Route::get('proveedores', [
'as' => 'admin.proveedores.index',
'uses' => 'ProveedoresController@index'
  ]);

  Route::get('proveedores/create', [
'as' => 'admin.proveedores.create',
'uses' => 'ProveedoresController@create'
  ]);

  Route::get('proveedores/edit/{proveedores}', [
'as' => 'admin.proveedores.edit',
'uses' => 'ProveedoresController@edit'
  ]);

   Route::post('proveedores/store', [
'as' => 'admin.proveedores.store',
'uses' => 'ProveedoresController@store'
  ]);

  Route::delete('proveedores/destroy/{proveedores}', [
'as' => 'admin.proveedores.destroy',
'uses' => 'ProveedoresController@destroy'
 ]);

  Route::put('proveedores/{proveedores}', [
'as' => 'admin.proveedores.update',
  'uses' => 'ProveedoresController@update'
  ]);
vipin93's avatar

see "jackfer" table exist or not and where u using jackfer

basosneo's avatar

jackfer is a database

    mysql> use jackfer
  Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A

 Database changed
 mysql> show tables
   -> ;
 +-------------------+
 | Tables_in_jackfer |
 +-------------------+
 | categories        |
 | migrations        |
 | order_items       |
 | orders            |
 | password_resets   |
 | products          |
 | proveedores       |
 | sessions          |
 | shoppingcart      |
 | users             |
 +-------------------+
 10 rows in set (0.00 sec)

I have never had a jackfer table, just the database ... this error arises because I tried to copy the user table I think, but I do not know how to work this error .. how can I fix it?

basosneo's avatar

That's the weird part of it is the database, I do not have it anywhere else

And already try doing migrate refresh, clearing cache, config clear and db: seed and nothing works for me

basosneo's avatar

i think that the error are here:

        public function store(SaveProveedoresRequest $request)
     {
       //return $request->all();
    $data = [
       'name'          => $request->get('name'),
       'last_name'     => $request->get('last_name'),
       'email'         => $request->get('email'),
       'user'          => $request->get('user'),
       'active'        => $request->has('active') ? 1 : 0,
       'address'       => $request->get('address'),
       'tel'           => $request->get('tel'),
       ];
    
      $proveedores = Proveedores::create($data);

       $message = $proveedores ? 'Nuevo proveedor agregado correctamente!' : 'El proveedor NO pudo agregarse!';
    
       return redirect()->route('admin.proveedores.index')->with('message', $message);
        
        }
    

      public function show(Proveedores $proveedores)
     {
    return $proveedores;
   }


     public function edit(Proveedores $proveedores)
     {
        return view('admin.proveedores.edit', compact('proveedores'));
      }



      public function update(Request $request, Proveedores $proveedores)
      {
         $this->validate($request, [
        'name'      => 'required|max:100',
        'last_name' => 'required|max:100',
        'email'     => 'required|exists:proveeders,email',
        'user'      => 'required|min:4|max:20',
        'address'   => 'required|max:100',
        'tel'       => 'required|min:4|max:20'
        ]);
    
      $proveedores->name = $request->get('name');
      $proveedores->last_name = $request->get('last_name');
       $proveedores->email = $request->get('email');
       $proveedores->user = $request->get('user');
       $proveedores->type = $request->get('type');
       $proveedores->address = $request->get('address');
     $proveedores->active = $request->has('active') ? 1 : 0;
        if($request->get('password') != "") $proveedores->password = $request->get('password');
    
        $updated = $proveedores->save();
    
        $message = $updated ? 'Proveedor actualizado correctamente!' : 'El Proveedor NO pudo actualizarse!';
    
        return redirect()->route('admin.proveedores.index')->with('message', $message);
     }

I have to say that this driver is a user controller but modified; I am trying to make a driver for providers.... maybe there is some conflict?

Snapey's avatar

the error is that jackfer.name does not exist.

this is database.table so laravel clearly thinks that there is a name table.

it's probably a bad eloquent relationship statement

vipin93's avatar

try to see whats the errors and if u have know idea then Google that, if not found then asked everyone will help u

Snapey's avatar

This error

QueryException in Connection.php line 647: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'jackfer.name' doesn't exist (SQL: select count(*) as aggregate from `name` where `name` = hola

check your email validation rule

basosneo's avatar

My rules are very similar and for the email are the ones I have put here, now I was looking again the code and I do not know how to get the update to work half (does not update but creates new ones), then there is the problem alone

    'email'     => 'required|email',

i delete the rule of email in mi 'Saveproveedoresrequest', but nothing change

vipin93's avatar

do not use request->get(); https://github.com/laravel/docs/pull/2269 u can use

$request->name,

or

 request->input('name')

and why using two times if using

Route::resource('proveedores', 'ProveedoresController'); 

then why again u using

  Route::post('proveedores/store', [
'as' => 'admin.proveedores.store',
'uses' => 'ProveedoresController@store'
  ]);

and follow right name pattern when u make model just simple use camonde

php artisan make:model Proveedore -m -c 

and if u updating then use update(); not save();

basosneo's avatar

Hey friends managed to fix that mistake and now I have another one.

Fix that error by adding the request to my model and changing the class of the saveproveedoresrequest;

 use Illuminate\Foundation\Http\FormRequest;
 class SaveProveedoresRequest extends FormRequest

for

  use Illuminate\Http\Request;
  use App\Proveedores;
  class SaveProveedoresRequest extends Request

Now the problem is that it does not take any data of my form everything is in null

   QueryException in Connection.php line 647: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null (SQL: insert into `proveedores` (`name`, `last_name`, `email`, `user`, `active`, `address`, `tel`, `updated_at`, `created_at`) values (, , , , 0, , , 2017-02-26 13:09:17, 2017-02-26 13:09:17))

If I in my model I add -> nullable () it creates an empty provider ignoring the data of my form

On the other hand if I add the class to my saveproveedores request, it returns the same error as jackfer.name

edit: @vipin93 Add all the advice you gave me, and prove to see if that worked for me, but the error remains the same, even so thanks for those little tips,

vipin93's avatar

its now clear that that its not requesting the vale of "name etc" now where u requesting the value in controller or in Request form(providers)

Next

Please or to participate in this conversation.