mercredi 17 janvier 2018

¿Why some of the attributes aren´t saving on my database?

I have the next error, when I try to create another user only some of the attributes are being saved in the database and the others aren´t. I´m new in Laravel and MySql and really can´t see the error. I hope you can help me. Thanks in advance.

When I check my database only some attributes are saved. "last_name", "user", "type", "active" and "address" aren´t being saved. The other two users where registered in phpMyAdmin that´s why they´re complete. Here´s the image:

!(http://ift.tt/2DotqDM)

Here´s migration file of my table:

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name', 100);
        $table->string('last_name', 100);
        $table->string('email');
        $table->string('user', 50);
        $table->string('password', 60);
        $table->enum('type', ['user', 'admin']);
        $table->boolean('active');
        $table->text('address');
        $table->rememberToken();
        $table->timestamps();
    });
}

This is my "store" method in my UserController:

public function store(SaveUserRequest $request)
{
    $data = [
        'name'          => $request->get('name'),
        'last_name'     => $request->get('last_name'),
        'email'         => $request->get('email'),
        'user'          => $request->get('user'),
        'password'      => $request->get('password'),
        'type'          => $request->get('type'),
        'active'        => $request->has('active') ? 1 : 0,
        'address'       => $request->get('address')
    ];
    $user = User::create($data);
    $message = $user ? 'Usuario agregado correctamente!' : 'El usuario NO pudo agregarse!';

    return redirect()->route('admin.user.index')->with('message', $message);
}

This one is my Request file:

<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class SaveUserRequest 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',
            'password'  => 'required|confirmed',
            'type'      => 'required|in:user,admin'
        ];
    }
}

And this is my create.blade.php:

@extends('admin.template')

@section('content')

<div class="container text-center">

    <div class="page-header">
        <h1>
            <i class="fa fa-user"></i> USUARIOS <small>[ Agregar usuario ]</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.user.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="user">Usuario:</label>

                        {!!
                            Form::text(
                                'user',
                                null,
                                array(
                                    'class'=>'form-control',
                                    'placeholder' => 'Ingresa el nombre de usuario...',
                                    //'required' => 'required'
                                )
                            )
                        !!}
                    </div>

                    <div class="form-group">
                        <label for="password">Password:</label>

                        {!!
                            Form::password(
                                'password',
                                array(
                                    'class'=>'form-control',
                                    //'required' => 'required'
                                )
                            )
                        !!}
                    </div>

                    <div class="form-group">
                        <label for="confirm_password">Confirmar Password:</label>

                        {!!
                            Form::password(
                                'password_confirmation',
                                array(
                                    'class'=>'form-control',
                                    //'required' => 'required'
                                )
                            )
                        !!}
                    </div>

                    <div class="form-group">
                        <label for="type">Tipo:</label>

                        {!! Form::radio('type', 'user', true) !!} User
                        {!! Form::radio('type', 'admin') !!} Admin
                    </div>

                    <div class="form-group">
                        <label for="address">Dirección:</label>

                        {!!
                            Form::textarea(
                                'address',
                                null,
                                array(
                                    'class'=>'form-control'
                                )
                            )
                        !!}
                    </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="" class="btn btn-warning">Cancelar</a>
                    </div>

                {!! Form::close() !!}

            </div>

        </div>
    </div>

</div>
@stop



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2mHJw0Y
via IFTTT

Aucun commentaire:

Enregistrer un commentaire