![](/img/trans.png)
[英]How can I store two foreign keys from the users table into a second table in Laravel 5.4?
[英]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();
});
}
上面的方法創建的用戶表幾乎沒有其他列,然后在用戶模型中添加了可填充內容,如下所示:
protected $fillable = ['name', 'email', 'password','mobile','team_id'];
我的create.blade.php視圖是:
@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
然后,我填好了表單中的所有字段,當我提出我得到的用戶名,密碼,email.I我沒有得到其他領域的“手機號碼”和“TEAM_ID”。(團隊ID是我在表單中輸入) fields-用戶名,密碼已保存,但手機和團隊未保存
我可以使用控制器來創建它,定義自己的路由並手動執行。但是,我不想這樣做。我想使用laravel 5.1中默認用於身份驗證的相同用戶模型。 我需要的是:::是否有任何方法可以使用默認存在於遷移中的users表在數據庫中創建和存儲這些列。
我將移動設備從整數更改為字符串並嘗試但無法將值輸入數據庫。我不想將輸入的值存儲在用戶表中。 誰能幫助我解決我的問題。
我正在使用bestmomo / scaffold軟件包。
public function up(){//}
就像模式生成器一樣,它將僅使用默認值(如果已指定)將列添加到表中,而不是實際數據。
如果要將數據添加到數據庫中。
/auth/register
路由映射AuthController
在App\\Http\\Controllers\\Auth
你必須overrride方法postRegister
在AuthController
下面是它可能看起來像
<?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');
}
}
並在你的routes.php
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.