How to insert values to table 'users' in laravel 5.2? - laravel-5

I want to insert employee details username,area to the table 'users'.
I have the following codes of CreateEmployeeController and
createemployee.blade.php view file.
When I click on the menu Create Employee is will shows the following error
QueryException in Connection.php line 662:
SQLSTATE[42000]: Syntax error or access violation: 1066 Table/alias: 'users' non unique (SQL: select * from users inner join users on users.id = users.users_id where users.deleted_at is null)
Controller file :
<?php
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Controllers\AdminController;
use App\CreateEmployee;
use App\Employee;
use App\Users;
class CreateEmployeeController extends AdminController
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
//
}
public function addemployee()
{
$employee = CreateEmployee::all();
$employee =CreateEmployee::join('users','users.id','=','users.users_id')->get();
return view('app.admin.employee.employee',compact('employee','users'));
}
public function employeesave(Request $request)
{
$title = 'Add Employee';
$employee = new Employee();
$employee->name=$request->employee_name;
$employee ->area = $request->area;
$employee->save();
Session::flash('flash_notification', array('level' => 'success', 'message' => 'employee created successfully'));
return Redirect::action('Admin\CreateEmployeeController#addemployee');
}
public function updateemployee(Request $request)
{
Employee::where('id',$request->id)->update(array('name'=>$request->employee_name,'area'=>$request->area));
Session::flash('flash_notification', array('level' => 'success', 'message' => 'shop details updated successfully'));
return Redirect::action('Admin\CreateEmployeeController#addemployee',array('id' => $request->id));
}
public function editemployee($id)
{
$employee = Employee::where('id',$id)->get();
return view('app.admin.employee.editemployee',compact('employee'));
}
public function deleteemployee($id)
{
$employee = Employee::where('id',$id)->get();
return view('app.admin.employee.delete',compact('employee'));
}
public function deleteconfirms($id)
{
$employee = Employee::where('id',$id)->delete();
Session::flash('flash_notification', array('level' => 'success', 'message' => 'customer deleted successfully'));
return Redirect::action('Admin\CreateEmployeeController#addemployee');
}
public function destroy($id)
{
//
}
}
//view file
#extends('app.admin.layouts.default')
{{-- Web site Title --}}
#section('title') {{{ trans('site/user.register') }}} :: #parent #stop
#section ('styles')
#parent
<style type="text/css">
</style>
#stop
{{-- Content --}}
#section('main')
#include('utils.vendor.flash.message')
<div class="row">
<div class="page-header">
<h2>Add Employee</h2>
</div>
</div>
<div class="container-fluid">
<div class="row">
#include('utils.errors.list')
<form class="form-horizontal" role="form" method="POST" action="{{ URL::to('admin/addemployee') }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="col-sm-12">
<div class="form-group">
<label class="col-md-2 control-label">Employee Name</label>
<div class="col-md-2">
<input type="text" class="form-control" name="employee_name"
required>
</div>
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<label class="col-md-2 control-label" for="religion">Password</label>
<div class="col-md-2">
<input type="password" class="form-control" placeholder="Password" name="password" id="password" data-parsley-trigger="change" data-parsley-required="true" data-parsley-minlength="6" data-parsley-maxlength="14" required>
{!! $errors->first('cpassword', '<label class="control-label" for="cpassword">:message</label>')!!}
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label class="col-md-2 control-label" for="caste">Confirm Password</label>
<div class="col-md-2">
<input type="password" class="form-control" placeholder="Confirm Password" name="password_confirmation" id="password_confirmation" data-parsley-trigger="change" data-parsley-required="true" data-parsley-equalto="#password" data-parsley-minlength="6" data-parsley-maxlength="14" required>
{!! $errors->first('password_confirmation', '<label class="control-label" for="password_confirmation">:message</label>')!!}
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label class="col-md-2 control-label">Area</label>
<div class="col-md-2">
<input type="text" class="form-control" name="area"
required placeholder="Area">
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-2 col-md-offset-2">
<button type="submit" class="btn btn-primary">
Add
</button>
</div>
</div>
</form>
</div>
</div>
<div class="invoice-content">
<div class="table-responsive">
<div class="col-md-offset-2">
<table class="table table-invoice">
<thead>
<tr>
<th>Employee Name</th>
<th>Area</th>
</tr>
</thead>
</div>
</div>
<tbody>
#foreach($addemployee as $employee)
<tr>
<td>{{$employee->employee_name}}</td>
<td>{{$employee->area}}</td>
<td>
Edit
<a onclick="return confirm('Are you Sure you want to do this Action!'); style.backgroundColor='#84DFC1'; " href="employee/delete/{{$employee->id}}">delete</a>
</td>
</tr>
#endforeach
#if(!count($employee))
<tr><td>NO data found </td></tr>
#endif
</tbody>
</tbody>
</table>
{{--</div>--}}
{{--</div>--}}
{{--</div>--}}
</div>
</div>
#endsection

I can't get the full idea about your problem, but as upto me I understand that - You are using same table/column names in your join statement, you can do this as:
$employee = CreateEmployee::join('users', 'create_employees.id','=', 'users.employee_id')->get();
Hope this helps!

Related

laravel livewire error Undefined variable $_instance

I have a form with which I add posts. I want to integrate CKEDITOR, to manipulate the content in textarea. to initialize the editor, I use the following code :
<script src="ckeditor/ckeditor.js">
ClassicEditor
.create(document.querySelector('#post_content'))
.then(editor=>{
editor.model.document.on('change:data',(e)=>{
#this('post_content').set('post_content', e.editor.getData());
});
})
.catch(error=>{
console.error(error);
});
</script>
When I submit form, I get the following error :
> Undefined variable $_instance
here's my form, I mention that without CKEDITOR, it works
<form wire:submit.prevent="addNewPost()" method="post" id="createPostForm" enctype="multipart/form-data">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-9">
<div class="mb-3">
<label for="" class="form-label">
Titlu
</label>
<input type="text" wire:model="post_title" name="post_title" class="form-control" placeholder="Titlul articolului" value="{{old('post_title')}}">
<span class=" text-danger ">#error('post_title') {{$message}}#enderror</span>
</div>
<div wire:ignore class="mb-3">
<label for="" class="form-label">
Continutul articolului
</label>
<textarea wire:model="post_content"class="ckeditor form-control" id="post_content" name="post_content" cols="30" rows="10" >{{$post_content}}</textarea>
<span class="text-danger">#error('post_content'){{$message}}#enderror</span>
</div>
</div>
<div class="col-md-3">
<div class="mb-3">
<div class="form-label">
Categoria articolului
</div>
<select wire:model="post_category" name="post_category" id="" class="form-select">
<option value="">--Nu ati ales nimic--</option>
#foreach (\App\Models\SubCategory::all() as $category)
<option value="{{$category->id}}">{{$category->subcategory_name}}</option>
#endforeach
</select>
<span class="text-danger">#error('post_category'){{$message}}#enderror</span>
</div>
<div class="mb-3">
<div class="form-label">
Imaginea articolului
</div>
<input type="file" wire:model="post_image" name="post_image" class="form-control">
<span class="text-danger ">#error('post_image'){{$message}}#enderror</span>
</div>
<div class="image-holder mb-2" style="max-width: 250px;">
<img src="" alt="" class="img-thumbnail" id="image-previewer" data-ijabo-default-img=''>
</div>
<button type="submit" id="sub" class="btn btn-primary">Salveaza</button>
</div>
</div>
</div>
</div>
</form>
And this is my component Posts.php
<?php
namespace App\Http\Livewire;
use App\Models\Post;
use Livewire\Component;
Use Livewire\WithFileUploads;
use App\Traits\ShowToastrTrait;
class Posts extends Component
{
use withFileUploads;
use showToastrTrait;
public $post_title, $post_content, $post_category, $post_image;
protected $rules = [
'post_title' => 'required|unique:posts,post_title|max:255',
'post_content' => 'required',
'post_image' => 'required|mimes:jpeg,png,jpg,gif,svg|max:2048',
'post_category' => 'required'];
protected $messages = [
'post_title.required' => 'Introduceti titlul articolului',
'post_title.unique' => 'Exista deja un asemenea titlu',
'post_content.required' => 'Introduceti continutul articolului',
'post_image.required' => 'Atasati o imagine articolului',
'post_image.mimes' => 'Imaginea trebuie sa fie in format jpeg/png/jpg/gif/svg',
'post_category.required' => 'Selectati categoria articolului',
];
public function addNewPost(){
dd($this);
$this->validate();
$post = Post::addNewPost($this);
if(!$post){
$this->showToastr('Articolul nu a putut fi adaugat','error');
}
$this->showToastr('Articolul a fost adaugat cu succes','success');
$this->reset();
}
public function render()
{
return view('livewire.posts');
}
}
I assume you have the script and the component view in separate files and that's why you get an error on #this('post_content').set('post_content', e.editor.getData()); line.
According to the docs, both should be placed in the same file (component file), then #this will be available in the script (you can read more about that here)
Example: let's assume you have a form component that will look like this:
<form>
<!-- your form elements -->
</form>
#push('scripts')
<script>
// accessing #this here should work
</script>
#endpush
Hope it helps :)

How to insert this array of mySbjects in a database?

I've been trying to insert this into the database and I don't have any idea how to store this information into the database... The relationship between user and grade is many-to-many and between grade and mySubject is One-to-many.
<div class="row">
#foreach($grades as $grade)
<div class="card shadow mx-2 my-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold">
<div class="custom-control custom-checkbox">
<input class="custom-control-input #error('grade') is-invalid #enderror" type="checkbox" id="{{$grade->id}}" name="grade[]" value="{{ $grade->id }}"/>
<label class="custom-control-label pt-1" for="{{$grade->id}}">{{$grade->name}}</label>
</div>
</h6>
</div>
<div class="card-body">
#foreach($grade->subjects as $subject)
<div class="custom-control custom-checkbox mb-2">
<input class="custom-control-input" type="checkbox" id="{{$grade->id}}{{$subject->id}}" name="mySubjects[{{$grade->id}}][]" value="{{ $subject->name }}"/>
<label class="custom-control-label" for="{{$grade->id}}{{$subject->id}}">
{{$subject->name}}
</label>
</div>
#endforeach
</div>
</div>
#endforeach
</div>
The store function
public function store(Request $request)
{
$user->grades()->sync($request->grade);
if($request->mySubjects){
//. . . .
}
}
}
Try below code:
public function store(Request $request)
{
$user->grades()->sync($request->grade);
if($request->mySubjects){
$mySubjects = $request-> mySubjects;
$data = [];
foreach($mySubjects as $subject){
array_push($data,
'your database field name'=> $subject,
'created_at' => now()->toDateTimeString(),
'updated_at' => now()->toDateTimeString(),
}
YourModelName::insert($data);
}
}
}

Insert foreign keys using eloquent laravel

I have 2 tables - questions and responses. I want to insert question_ids for every answer given into responses' table(a survey system). I have been able to insert answers, but not corresponding question_ids into responses' table.Here is my controller.
public function store(Request $request)
{
for($i=1; $i<=count($request->answer); $i++)
{
$answers[] = [
'answer' => $request->answer[$i],
'question_id' => $request->question_id];
}
Response::insert($answers);
}
// View
<div class="form">
<div id="successmessage">Survey sent successful. Thank you!</div>
<div id="errormessage">Errors</div>
<form action="{{ route('surveys.store') }}" method="post" role="form" class="surveyForm">
#csrf
<?php
;$count=1;
?>
#foreach($survey->questions as $question)
#switch($question->input_type)
#case('text')
#case('email')
<div class="form-group">
<input type="{{$question->input_type}}" name="answer[{{$count}}]" class="form-control"
id="{{strtolower($question->qtn)}}" placeholder="{{$question->qtn}}"
data-rule="{{$question->data_rule}}" data-msg="{{$question->data_message}}" />
<div class="validation"></div>
</div>
#break
#case('textarea')
<div class="form-group">
<textarea class="form-control" name="answer[{{$count}}]" rows="5" data-rule="{{$question->data_rule}}" data-msg="{{$question->data_message}}" placeholder="{{$question->qtn}}"></textarea>
<div class="validation"></div>
</div>
#break
#endswitch
<?php $count++; ?>
#endforeach
<div class="text-center">
<button type="submit">Send</button>
</div>
</form>
</div>

Validating forms on laravel

Hi i getting this error When I try to validate a form, with this
$this->validate($request, [
'documento' => 'required|unique:cliente|max:55',
]);
htmlentities() expects parameter 1 to be string, array given (View: C:\sisVentas\resources\views\ventas\cliente\create.blade.php)
this is my view please help.
#extends ('layouts.admin')
#section ('contenido')
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<h3>Nuevo Cliente</h3>
#if (count($errors)>0)
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{$error}}</li>
#endforeach
</ul>
</div>
#endif
</div>
{!!Form::open(array('url'=>'ventas/cliente','method'=>'POST','autocomplete'=>'off', 'files'=>'true'))!!}
{{Form::token()}}
<div class="row">
<div class="col-lg-6 col-sm-6 col-md-6 col-xs-12">
<div class="form-group">
<label for="empresa">Empresa</label>
<input type="text" name="empresa" value="{{old('empresa')}}" class="form-control"
placeholder="Empresa...">
</div>
</div>
<div class="col-lg-6 col-sm-6 col-md-6 col-xs-12">
<div class="form-group">
<label for="contacto">Direccion</label>
<input type="text" name="direccion" value="{{old('direccion')}}" class="form-control"
placeholder="Direccion...">
</div>
</div>
<div class="col-lg-6 col-sm-6 col-md-6 col-xs-12">
<div class="form-group">
<label>Tipo Documento</label>
<select name="tipo_documento" class="form-control">
<option value="J">J</option>
<option value="G">G</option>
<option value="V">V</option>
<option value="E">E</option>
</select>
</div>
</div>
<div class="col-lg-6 col-sm-6 col-md-6 col-xs-12">
<div class="form-group">
<label for="Numero de documento">Numero de Documento</label>
<input type="text" name="documento" id="documento" required value="{{old('documento')}}"
onkeypress='return event.charCode >= 48 && event.charCode <= 57' class="form-control"
placeholder="Numero de Documento...">
</div>
</div>
<div class="col-lg-6 col-sm-6 col-md-6 col-xs-12">
<div class="form-group">
<label for="razon_social">Razon Social</label>
<input type="text" name="razon_social" value="{{old('razon_social')}}" class="form-control"
placeholder="Razon social...">
</div>
</div>
</div>
<div class="row">
<div class="panel panel-primary">
<div class="panel-body">
<div class="col-lg-2 col-sm-2 col-md-2 col-xs-12">
<div class="form-group">
<label for="nombre">Nombre</label>
<input type="text" name="pnombre" id="pnombre" class="form-control" placeholder="Nombre...">
</div>
</div>
<div class="col-lg-5 col-sm-5 col-md-5 col-xs-12">
<div class="form-group">
<label for="telefonos">Telefonos</label>
<input type="text" name="ptelefono" id="ptelefono" class="form-control"
value="{{old('precio')}}" placeholder="Telefonos...">
</div>
</div>
<div class="col-lg-3 col-sm-3 col-md-3 col-xs-12">
<div class="form-group">
<label for="correo">Correo</label>
<input type="text" name="pcorreo" id="pcorreo" class="form-control"
value="{{old('correo')}}" placeholder="correo...">
</div>
</div>
<div class="col-lg-2 col-sm-2 col-md-2 col-xs-12">
<div class="form-group">
<button type="button" id="bt_add" class="btn btn-primary">Agregar</button>
</div>
</div>
<div class="col-lg-8 col-sm-8 col-md-8 col-xs-12">
<table id="detalles" class="table table-striped table-bordered table-condensed">
<thead style="background-color: #ccc">
<th>Opciones</th>
<th>Nombre</th>
<th>Contacto</th>
<th>Correo</th>
</thead>
<tfoot>
<th></th>
<th></th>
<th></th>
<th></th>
</tfoot>
<tbody>
</tbody>
</table>
<div class="col-lg-6 col-sm-6 col-md-6 col-xs-12">
<div class="form-group">
<button class="btn btn-primary" id="guardar" type="submit">Guardar</button>
<button class="btn btn-danger" type="reset">Cancelar</button>
</div>
</div>
</div>
{!!Form::close() !!}
#push ('scripts') <!-- Trabajar con el script definido en el layout-->
<script>
//////////
$('#guardar').hide();
$(document).ready(function () {
$('#bt_add').click(function () {
agregar();
});
});
var cont = 0;
var total = 0;
subtotal = [];
function agregar() {
nombre = $('#pnombre').val();
telefono = $('#ptelefono').val();
correo = $('#pcorreo').val();
if (nombre != "" && telefono != "") {
total = total + subtotal[cont];
var fila = '<tr class="selected" id="fila' + cont + '"><td><button type="button" class="btn btn-warning" onclick="eliminar(' + cont + ')" >X</button></td><td><input type="text" name="nombre[]" value="' + nombre + '"</td><td><input type="text" name="telefono[]" value="' + telefono + '"</td><td><input type="text" name="correo[]" value="' + correo + '"</td></tr>';
cont++;
limpiar();
$('#detalles').append(fila);
$('#guardar').show();
} else {
alert("Error al ingresar los detalles del contacto, revise los datos del contacto ");
}
}
function limpiar() {
$('#pnombre').val("");
$('#ptelefono').val("");
$('#pcorreo').val("");
}
function eliminar(index) {
$("#fila" + index).remove();
evaluar();
}
</script>
#endpush
#endsection
and this is my controller
<?php
namespace sisVentas\Http\Controllers;
use Illuminate\Http\Request;
use sisVentas\Http\Requests;
use sisVentas\Persona;
use sisVentas\Contacto;
use Response;
use sisVentas\Evento;
use Carbon\Carbon;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use sisVentas\Http\Requests\PersonaFormRequest;
use DB;
class ClienteController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index(Request $request)
{
if ($request)
{
$query=trim($request->get('searchText'));
$clientes=DB::table('cliente')
->where ('empresa','LIKE','%'.$query.'%')
->orwhere ('tipo_documento','LIKE','%'.$query.'%')
->orwhere ('documento','LIKE','%'.$query.'%')
->orwhere ('direccion','LIKE','%'.$query.'%')
->orwhere ('razon_social','LIKE','%'.$query.'%')
->orderBy('codigo_cliente','desc')
->paginate(7);
return view('ventas.cliente.index',["clientes"=>$clientes,"searchText"=>$query]);
}
}
public function create()
{
return view("ventas.cliente.create");
}
public function store (Request $request)
{
$this->validate($request, [
'documento' => 'required|unique:cliente|max:55',
]);
try {
DB::beginTransaction();
$persona=new Persona;
$persona->tipo_documento=$request->get('tipo_documento');
$persona->documento=$request->get('documento');
$persona->empresa=$request->get('empresa');
$persona->direccion=$request->get('direccion');
$persona->razon_social=$request->get('razon_social');
$persona->save();
$id = $persona->codigo_cliente;
$evento=new Evento;
$user = Auth::id();
$evento->cod_usuario=$user;
$evento->tabla='Cliente';
$evento->accion='Nuevo Ingreso';
$evento->codigo_referencia=$id;
$mytime = Carbon::now(' America/Caracas');
$evento->fecha =$mytime->toDateTimeString();
$evento->save();
$nombre=$request->get('nombre');
$telefono = $request->get('telefono');
$correo = $request->get('correo');
$cont = 0;
while ($cont < count($nombre)) {
# code...
$detalle = new Contacto();
$detalle->idempresa=$id;
$detalle->nombre=$nombre[$cont];
$detalle->telefono=$telefono[$cont];
$detalle->correo=$correo[$cont];
$detalle->save();
$cont=$cont+1;
}
DB::commit();
} catch (\Exception $e) {
DB::rollback();
}
return Redirect::to('ventas/cliente/create');
}
public function show($id)
{
return view("ventas.cliente.show",["persona"=>Persona::findOrFail($id)]);
}
public function edit($id)
{
return view("ventas.cliente.edit",["persona"=>Persona::findOrFail($id)]);
}
public function update(PersonaFormRequest $request,$id)
{
$persona=Persona::findOrFail($id);
$persona->tipo_documento=$request->get('tipo_documento');
$persona->documento=$request->get('documento');
$persona->empresa=$request->get('empresa');
$persona->direccion=$request->get('direccion');
$persona->razon_social=$request->get('razon_social');
$persona->update();
$evento=new Evento;
$user = Auth::id();
$evento->cod_usuario=$user;
$evento->tabla='Cliente';
$evento->accion='Modificacion';
$evento->codigo_referencia=$id;
$mytime = Carbon::now(' America/Caracas');
$evento->fecha =$mytime->toDateTimeString();
$evento->save();
return Redirect::to('ventas/cliente');
}
public function destroy($id)
{
$persona=Persona::findOrFail($id);
$clientes = DB::table('cliente')->where('codigo_cliente', '=', $id)->delete();
$persona->update();
$evento=new Evento;
$user = Auth::id();
$evento->cod_usuario=$user;
$evento->tabla='Cliente';
$evento->accion='Eliminar';
$evento->codigo_referencia=$id;
$mytime = Carbon::now(' America/Caracas');
$evento->fecha =$mytime->toDateTimeString();
$evento->save();
return Redirect::to('ventas/cliente');
}
}
this issue appear because one of the value that is between the {{}} returning an array instead of string.
and i think it is in the following code
<input type="text" name="pcorreo" id="pcorreo" class="form-control" value="{{old('correo')}}" placeholder="correo...">
and as I saw in your view code you have an input with name correo[] that is an array, and after the validation failure the controller redirect to the form view, the old('correo') function return an array instead of string

how can I add columns for App\User and store the data to in users table in laravel 5.1?

public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password', 60);
$table->integer('mobile');
$table->integer('status')->default(0);
$table->integer('team_id');
$table->string('created_by');
$table->string('updated_by');
$table->rememberToken();
$table->timestamps();
});
}
The above method creates user table with few additional columns.I then added fillable content in my User model as:
protected $fillable = ['name', 'email', 'password','mobile','team_id'];
My create.blade.php view is:
#extends('master')
#section('title','Creating.. User')
#section('content')
<div class="container-fluid">
<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">
#if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form class="form-horizontal" role="form" method="POST" action="{{ url('/auth/register') }}">
{!! csrf_field() !!}
<div class="form-group">
<label class="col-md-4 control-label">Name</label>
<div class="col-md-6">
<input type="text" class="form-control" name="name" value="{{ old('name') }}">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input type="email" class="form-control" name="email" value="{{ old('email') }}">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input type="password" class="form-control" name="password">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Confirm Password</label>
<div class="col-md-6">
<input type="password" class="form-control" name="password_confirmation">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Mobile</label>
<div class="col-md-6">
<input type="number" class="form-control" name="mobile">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Team</label>
<div class="col-md-6">
<input type="number" class="form-control" name="team_id">
</div>
</div>
<!--
<div class="form-group">
<label class="col-md-4 control-label">Role</label>
<div class="col-md-6">
<input type="text" class="form-control" name="role">
</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
Then,I filled all the fields in the form and when I submit I get username,password,email.I am not getting other fields "mobile number" and "team_id".(Team Id is what I enter in the form)
fields- username,password is saved but mobile and team aren't
I can create this with controller,defining my own routes and do it manually.But,I don't want to do that.I want to use the same User model that comes default for authentication in laravel 5.1.
What I need is ::: Is there any way to create and store these columns in the database with the users table that exists in migration by default.
I changed the mobile from integer to string and tried but couldn't get the values into the database.I wan't the values that I enter to get stored in my users table. Can anyone help me to solve my problem.
I am using bestmomo/scaffold package.
public function up(){//} is like schema builder, it will only add columns to your table with default values if specified but not actual data.
If you want to add data to your database./auth/register route maps to AuthController in App\Http\Controllers\Auth
You have to overrride the method postRegister in AuthController
Here is how it might look like
<?php namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\Registrar;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use App\User;
use Illuminate\Http\Request;
use Hash;
class AuthController extends Controller {
public function postRegister(Request $request){
$user = new User();
$user->name = ucwords($request->input('name'));
$user->email = strtolower($request->input('email'));
$user->phone = $request->input('phone');
$user->address = $request->input('address');
$user->password = Hash::make($request->input('password'));
$user->save();
return redirect('/donner');
}
}
and in your routes.php
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);

Resources