Laravel 5.2 Admin创建像cms这样的用户

时间:2016-12-18 23:43:41

标签: laravel-5 laravel-5.2 content-management-system

我不太了解laravel中的登录和注册认证机制,因为它们隐藏了它并且我还是新手。
我想让更多用户使用管理员帐户我使用laravel提供的用户模型注册的。可能吗?我需要制作另一个模型吗?

当我提交表格时 screenshot 我希望它存储在数据库中并转到用户列表页面。但他们都没有发生。谢谢你的帮助。

路由

Route::get('/pengguna/tambah', 'Auth\UserController@viewCreateForm');
Route::post('/pengguna/tambah', 'Auth\UserController@store');

UserController中

namespace App\Http\Controllers\Auth;

use App\User;
use App\Http\Requests\UserDataRequest;
use Auth;
use App\Http\Controllers\Controller;
use Illuminate\Support\Str; 
use Illuminate\Support\Facades\Input;
use Illuminate\Http\Request;
public function viewCreateForm()
    {

          return view('/auth/create_user');

    }
 public function store(UserDataRequest $request)
    {   

            $user=new User;
            $user->username=$request->get('nama_pengguna');
            $user->password=bcrypt($request->get('password_pengguna'));

            $user->name=$request->get('nama_lengkap');


            $user->email="aae@mail.com";
            $user->role="user";



           $msg="Pengguna baru berhasil ditambahkan";


            $user->save();
            $request->session()->flash('flash_message',$msg);
            return redirect('/');

    }

users table

用户

    <?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
     protected $table='users';

    protected $fillable = [
        'name', 'username', 'email', 'password', 'role'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}

/ AUTH / create_user

@extends('master')

@section('content')
<section id="main-content">
    <section class="wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header"><i class="icon-users"></i> Admin</h3>
                <ol class="breadcrumb">
                    <li><i class="fa fa-home"></i><a href="{{url('/')}}">Beranda</a></li>
                    <li>Admin</li>
                    <li>Tambah Admin</li>
                </ol>
            </div>
        </div>

        <!-- Form validations -->
        <div class="row">
            <div class="col-lg-12">
                <section class="panel">
                    <header class="panel-heading">
                        Form Registrasi Admin
                    </header>
                    <div class="panel-body">

                        <form class="form-validate form-horizontal" id="register_form" method="POST" action="{{ url('/pengguna/tambah') }}" role="form" enctype="multipart/form-data">
                            <input type="hidden" name="_token" value="{{csrf_token()}}">

                            <div class="form-group ">
                                <label for="cname" class="control-label col-lg-2">Username <span class="required">*</span></label>
                                <div class="col-lg-4">
                                    <input class="form-control" id="username" name="nama_pengguna" value="{{old('nama_pengguna')}}" minlength="5" maxlength="12" type="text" required />

                                </div>

                            </div>
                            <div class="form-group ">
                                <label for="password" class="control-label col-lg-2">Password <span class="required">*</span></label>
                                <div class="col-lg-4">
                                    <input class="form-control " id="password" name="password_pengguna" type="password" value="{{old('password_pengguna')}}" />
                                </div>
                            </div>
                            <div class="form-group ">
                                <label for="confirm_password" class="control-label col-lg-2">Konfirmasi Password <span class="required">*</span></label>
                                <div class="col-lg-4">
                                    <input class="form-control " id="confirm_password" name="confirm_password" type="password" value="{{old('confirm_password')}}" />
                                </div>
                            </div>

                            <div class="form-group ">
                                <label for="fullname" class="control-label col-lg-2">Nama Lengkap <span class="required">*</span></label>
                                <div class="col-lg-4">
                                    <input class=" form-control" id="fullname" name="nama_lengkap" type="text" value="{{old('nama_lengkap')}}" />
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-lg-offset-2 col-lg-10">
                                    <input name="tambah" type="submit" class="btn btn-primary" value="Daftarkan">
                                    <button class="btn btn-primaryCancel" type="button">Batal</button>
                                </div>
                            </div>
                        </form>


                    </div>

                </section>
            </div>
        </div>
    </section>
</section>
@endsection

1 个答案:

答案 0 :(得分:0)

为多个用户使用角色管理

https://cartalyst.com/manual/sentinel/2.0