点击注册后没有像教程里弹出用户信息界面,没有传值到数据库
我的项目叫w2_support, 按照教程操作,点注册按钮以后跳出空白页, 显示http://w2_support.com/users 。 然后查看数据库里面没有值传入。
我的环境是win10+官方原版homestead,非教程里的定制版,但是其他该装的东西都装了。
对比过教程源码,该修改的都修改了,不知道还能怎么办?头都大了,求大神指点一下,不胜感激!
这是我的路由:
Route::get('/', 'PageController@home')->name('home');
Route::get('/help', 'PageController@help')->name('help');
Route::get('/about', 'PageController@about')->name('about');
Route::get('register', 'UsersController@create')->name('register');
Route::resource('users', 'UsersController');
这是控制器:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Models\User;
class UsersController extends Controller
{
public function create()
{
return view('users.register');
}
public function show(User $user)
{
return view('users.show', compact('user'));
}
public function store(Request $request)
{
$this->validate($request, [
'name' => 'required|max:50',
'email' => 'required|email|unique:users|max:255',
'password' => 'required|confirmed|min:6'
]);
return;
$user = User::create([
'name' => $request->name,
'email' => $request->email,
'password' => bcrypt($request->password),
]);
session()->flash('success', 'New User Successfully Registered!');
return redirect()->route('users.show', [$user]);
}
}
这是env文件:
APP_NAME=w2_support
APP_ENV=local
APP_KEY=base64:8n5Fps5BUl4LJ9qU/lx/9XEYVy5xlz0Zoj1cgo7z43Q=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=w2_support
DB_USERNAME=homestead
DB_PASSWORD=secret
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
User.php
<?php
namespace App\Models;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
}
show.blade.php
@extends('layout.default')
@section('title', $user->name)
@section('content')
<div class="row">
<div class="col-md-offset-2 col-md-8">
<div class="col-md-12">
<div class="col-md-offset-2 col-md-8">
<section class="user_info">
@include('shared._user_info', ['user' => $user])
</section>
</div>
</div>
</div>
</div>
@stop
部分注册页面 register.blade.php (我取名为register)
@extends('layout.default')
@section('title', 'Register')
@section('content')
<div class="col-md-offset-2 col-md-8">
<div class="panel panel-default">
<div class="panel-heading">
<h5>New User Register</h5>
</div>
<div class="panel-body">
@include('shared._errors')
<form method="POST" action="{{ route('users.store') }}">
{{ csrf_field() }}
<div class="form-group">
<label for="name">Full Name: </label>
<input type="text" name="name" class="form-control" value="{{ old('name') }}">
</div>
推荐文章: