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

basosneo's avatar

in my controller in store function

      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);
        
       }

PD: is fixed the update error now, but This method of creating this difficult

basosneo's avatar

With dd and I got an empty array

  <pre class="sf-dump" id="sf-dump-1230941108" data-indent-pad="  ">[]
  </pre>
  <script>Sfdump("sf-dump-1230941108")</script>
Snapey's avatar

As said by @vipin93, don't use get for your request data

You could pass the request object to the create or update method, but then you are left with handling the checkbox value.

Fix the above;

    $data = [
       'name'          => $request->name,
       'last_name'     => $request->last_name,
       'email'         => $request->email,
       'user'          => $request->user,
       'active'        => $request->has('active') ? 1 : 0,
       'address'       => $request->address,
       'tel'           => $request->tel
       ];
    
    $proveedores = Proveedores::create($data);

or

    $data = $request('name','last_name','email','user','address','tel');

    $data['active'] = $request->has('active') ? 1 : 0;

    $proveedores = Proveedores::create($data);


1 like
basosneo's avatar

Yes, I have proved it in various ways, but nothing; I still get the same problem ..

   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 14:01:13, 2017-02-26 14:01:13))

maybe it's because my request is request and not formrequest? But if I change it it will re-generate the table error

vipin93's avatar
public function store(SaveProveedoresRequest $request)
    {
    dd($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);
        
       }
basosneo's avatar

With all I get an empty array

  dd($request->all());

 return $request->all();

With this I had an error for the ';' But when I removed it I left the empty array

 dd($request->all(););
vipin93's avatar

it means its not requesting form but it should show "NULL"

basosneo's avatar

Just show me the empty array in all the ways i tried it ..

If I let the function go normal on line 2 I get this

    at Connection->runQueryCallback('insert into `proveedores` (`name`, `last_name`, `email`, `user`, `active`, `address`, `tel`, `updated_at`, `created_at`) values (?, ?, ?, ?, ?, ?, ?, ?, ?)', array(null, null, null, null, 0, null, null, '2017-02-26 14:09:34', '2017-02-26 14:09:34'), object(Closure)) in Connection.php line 607
vipin93's avatar

dd($request->all()); dont return and show your providers(full code)

basosneo's avatar

my 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'];
  }
basosneo's avatar
   <?php

   namespace App\Http\Requests;


   use Illuminate\Http\Request;
   use App\Proveedores;

   class SaveProveedoresRequest extends Request
  {
     /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
     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|exists:proveeders,email',
        'user'      => 'required|min:4|max:20',
        'tel'       => 'required|max:30000000',
        'address'   => 'required|max:100',
        
        ];
    }
   }
basosneo's avatar

yes i tried but nothing

   namespace App\Http\Requests;

  use Illuminate\Foundation\Http\FormRequest;
 use Illuminate\Http\Request;
 use App\Proveedores;

  class SaveProveedoresRequest extends Request

if i change the extends to Formrequest i have the error

   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)
basosneo's avatar

yes i know...

i said you; if i change the extends to Formrequest i have the error

     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)

Now, i copy and paste the saveuserrequest and modify a couple of codes, so this is working for me with errors in integer

  'tel'  => 'required|max:21|integer'

i cant put any normal telf '646541434' (fake telf)

vipin93's avatar

try to do without "SaveProveedoresRequest" and see clearly saying " jackfer.name" not found then check maybe u misspelled or using wrong table

basosneo's avatar

I change all and now is Work, but:

   <?php

  namespace App\Http\Requests;

  use App\Http\Requests\Request;

 class SaveProveedoresRequest extends Request
    {
    /**
    * Determine if the user is authorized to make this request.
    *
    * @return bool
    */
    public function authorize()
   {
    return true;
   }

    /**
    * Get the validation rules that apply to the request.
    *
    * @return array
    */
    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:21',
        'address'      => 'required|max:255'
        ];}
       }

i have one error whit 'tel' the integer method dont give me the oportunity to register a normal number

basosneo's avatar

Yes, I can not put an amyo number to 4 digits even though I can get a max of 21, I think it's because of the integer

Snapey's avatar

I suggested before. .....

Don't save phone number as integer

INT has max range -2147483648 to 2147483647

Unsigned max 4294967295

So it won't store your phone number.

You appear to still have the form request incorrect. The top lines should be;

<?php
namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class SaveProveedoresRequest extends FormRequest
{

Your store method, to use the above request;

use App\Http\Requests\SaveProveedoresRequest;


public function store (SaveSaveProveedoresRequest $request)
{
//
1 like
basosneo's avatar

And try to change them and if it is the only way they work

i change to string the 'tel' table. how i can restringer to only number of telef?

basosneo's avatar

Thank you, I have seen many videos, but it is always good to keep informed

basosneo's avatar

Hey @snapey as I do so that users can only add letters and spaces in the 'name' and 'last_name'

Please or to participate in this conversation.