使用模态对话框laravel创建编辑函数
我设法让我的创建功能使用模式弹出视图工作,现在我想做同样的编辑功能,但我似乎不知道怎么做。有人能帮我解决吗?我的创建方法如下所示 php(我已经指定了这两个路由) blade.php使用模态对话框laravel创建编辑函数,laravel,modal-dialog,laravel-5.1,Laravel,Modal Dialog,Laravel 5.1,我设法让我的创建功能使用模式弹出视图工作,现在我想做同样的编辑功能,但我似乎不知道怎么做。有人能帮我解决吗?我的创建方法如下所示 php(我已经指定了这两个路由) blade.php ... <button type="button" class="btn btn-info btn-md" data-toggle="modal" data-target="#register">Register New User</button>class="glyphicon glyp
...
<button type="button" class="btn btn-info btn-md" data-toggle="modal" data-target="#register">Register New User</button>class="glyphicon glyphicon-edit"></i></button>
<button class="btn btn-sm btn-warning" type="button" data-toggle="modal" data-target="#update">Edit <i class="glyphicon glyphicon-edit"></i></button>
<!-- Modal -->
<div id="register" class="modal fade" role="dialog">
...
StoreNewUserRequest.php(验证)
...
<button type="button" class="btn btn-info btn-md" data-toggle="modal" data-target="#register">Register New User</button>class="glyphicon glyphicon-edit"></i></button>
<button class="btn btn-sm btn-warning" type="button" data-toggle="modal" data-target="#update">Edit <i class="glyphicon glyphicon-edit"></i></button>
<!-- Modal -->
<div id="register" class="modal fade" role="dialog">
...
class ManageAccountsController extends Controller
{
public $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function index()
{
$users = User::orderBy('name')->get();
$roles = Role::all();
return view('manage_accounts', compact('users', 'roles'));
}
public function register(StoreNewUserRequest $request)
{
// process the form here
$this->userRepository->upsert($request);
Session::flash('flash_message', 'User successfully added!');
return redirect()->back();
}
}
class UserRepository {
public function upsert($data)
{
// Now we can separate this upsert function here
$user = new User;
$user->name = $data['name'];
$user->email = $data['email'];
$user->password = Hash::make($data['password']);
$user->mobile = $data['mobile'];
$user->role_id = $data['role_id'];
// save our user
$user->save();
return $user;
}
}
<?php
namespace App\Http\Requests;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Input;
use App\Http\Requests\Request;
class StoreNewUserRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
// create the validation rules ------------------------
return [
'name' => 'required', // just a normal required validation
'email' => 'required|email|unique:users', // required and must be unique in the user table
'password' => 'required|min:8|alpha_num',
'password_confirm' => 'required|same:password', // required and has to match the password field
'mobile' => 'required',
'role_id' => 'required'
];
}
}