我是Laravel的新用户,尝试从数据库中将用户类型添加到注册刀片页面中,但每次出现相同错误时,它都会给我 未定义的变量:uTypes(视图:/Applications/MAMP/htdocs/creativeapp/resources/views/auth/register.blade.php)
路线代码web.php:
Route::get('/auth/register', 'UsersController@index');
控制器代码UsersController.php:
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
class UsersController extends Controller {
public function index() {
$uTypes = DB::table('userstype')->pluck("type_name", "id");
return view('auth.register', ['uTypes' => $uTypes]);
}
}
查看代码register.blade.php:
<div class="form-group row">
<label for="usertype" class="col-md-4 col-form-label text-md-right">{{ __('User Type') }}</label>
<div class="col-md-6">
<select name="userType" class="form-control">
<option value="">--Select Type--</option>
@foreach ($uTypes as $ut => $value)
<option value="{{ $ut }}"> {{ $value }}</option>
@endforeach
</select>
</div>
</div>
答案 0 :(得分:0)
您不需要重写Route,使用auth本机路由。
您需要将status
方法覆盖到groups
中。
app / Http / Controllers / Auth / RegisterController.php
const data = [
{
otherProperty: "string",
otherPropertyTwo: "string",
personId: "1269",
peopleGroups: [
{ group: "SENIORS", groupStatus: "paid" },
{ group: "Infants", groupStatus: "not_paid" }
]
}
];
const statusArrayUpdate = data.map(({ personId, peopleGroups }) => ({
personId,
groups: peopleGroups.map(({ group, groupStatus }) => ({
group,
status: groupStatus
}))
}));
console.log(statusArrayUpdate)
然后,别忘了更新验证器,迁移和创建方法