本文整理汇总了PHP中Entrust::hasRole方法的典型用法代码示例。如果您正苦于以下问题:PHP Entrust::hasRole方法的具体用法?PHP Entrust::hasRole怎么用?PHP Entrust::hasRole使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Entrust
的用法示例。
在下文中一共展示了Entrust::hasRole方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next, $role)
{
if (\Auth::check() && !\Entrust::hasRole($role)) {
return redirect()->back();
}
return $next($request);
}
示例2: isAdmin
public static function isAdmin()
{
if (!Entrust::hasRole('admin')) {
return false;
}
return true;
}
示例3: index
/**
* Display a listing of rateinquiries
*
* @return Response
*/
public function index()
{
//RateInquiry::where('viewed', 0)->where('status', 1)->update(array('viewed'=> 1));
$from = null;
$to = null;
if (Input::has('search')) {
//dd(Input::all());
$from = Input::get('from');
$to = Input::get('to');
if (Entrust::hasRole('Admin')) {
$user_id = Input::get('agent_id');
$rateinquiries = RateInquiry::whereHas('user', function ($q) use($user_id) {
$q->where('users.id', 'like', '%' . $user_id . '%');
});
} elseif (Entrust::hasRole('Agent')) {
$rateinquiries = RateInquiry::whereHas('user', function ($q) {
$q->where('users.id', '=', Auth::id());
});
}
if (!empty($from) && !empty($to)) {
$rateinquiries = $rateinquiries->where('from', '>=', $from)->where('to', '<=', $to);
}
$rateinquiries = $rateinquiries->get();
} else {
if (Entrust::hasRole('Admin')) {
$rateinquiries = RateInquiry::orderBy('updated_at', 'desc')->get();
} elseif (Entrust::hasRole('Agent')) {
$rateinquiries = RateInquiry::where('user_id', Auth::id())->orderBy('updated_at', 'desc')->get();
}
}
return View::make('inquiries.rate-inquiries.index', compact('rateinquiries', 'user_id', 'from', 'to'));
}
示例4: allowed
public function allowed($sAction = null, $sRole = null)
{
if (static::isAdmin() || \Entrust::hasRole('admin') || \Entrust::can($sAction) || \Entrust::hasRole($sRole)) {
return true;
}
return false;
}
示例5: getCreditLimit
public static function getCreditLimit($agent_id)
{
if (Entrust::hasRole('Agent')) {
return Agent::where('user_id', $agent_id)->first()->credit_limit;
}
return false;
}
示例6: userHasAgent
public static function userHasAgent()
{
if (Entrust::hasRole('Agent')) {
if ($x = User::getAgentOfUser(Auth::user())) {
return Agent::with('market')->find($x->agent_id);
}
}
return false;
}
示例7: __construct
public function __construct()
{
$this->_user = Auth::user();
$this->_parameters = Route::current()->parameters();
if (!User::hasHotelPermission($this->_user, $this->_parameters['hotels'])) {
if (!Entrust::hasRole('Admin')) {
App::abort(403);
}
}
}
示例8: destroy
public function destroy(Comment $comment)
{
if ($comment->user_id != Auth::user()->id && !Entrust::hasRole('admin')) {
return redirect()->back()->withErrors(config('constants.INVALID_LINK'));
}
$belongs_to = $comment->belongs_to;
$comment->delete();
$activity = 'Deleted a commented on a ' . ucfirst($belongs_to);
Activity::log($activity);
return redirect()->back()->withSuccess(config('constants.DELETED'));
}
示例9: getInDebugModeAttribute
public function getInDebugModeAttribute()
{
//限管理員
if (!\Entrust::hasRole('admin')) {
return false;
}
if (!$this->debug) {
return false;
}
return true;
}
示例10: postDestroy
public function postDestroy($id)
{
if (\Entrust::hasRole('Admin')) {
$category = Category::find($id);
if ($category) {
$category->delete();
return redirect('admin/categories/view')->with('flash_message', 'Category deleted');
}
}
return redirect('admin/categories/view')->with('flash_message', 'You unable to delete categories due to Demo account');
}
示例11: login
/**
* Login with the provided username & password in local first, if
* failed, try login in center.
*
* @param Request
* @return Json
*/
public function login(Request $request)
{
$username = $request->input('username');
$password = $request->input('password');
// if login failed
if (!Auth::attempt(['username' => $username, 'password' => $password]) && self::loginCheckSSO($username, $password) === 'SUCCESS') {
$user = User::where('username', '=', $username)->first();
Auth::login($user);
}
$response = ['is_student' => \Entrust::hasRole('student'), 'is_manager' => \Entrust::hasRole('manager'), 'status' => Auth::check()];
return response()->json($response);
}
示例12: store
/**
* Store a newly created payment in storage.
*
* @return Response
*/
public function store()
{
$data = Input::all();
$user_id = Auth::id();
$validator = Validator::make(Input::all(), array('amount' => 'required|numeric'));
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}
/**
* Payments are starting from "BK" numbers
*/
if ($x = Payment::find(Payment::max('id'))) {
$y = (int) substr($x->reference_number, 2);
$data['reference_number'] = 'BK' . ++$y;
} else {
$data['reference_number'] = 'BK10000000';
}
$data['agent_id'] = User::getAgentOfUser(Auth::id());
if (Entrust::hasRole('Agent')) {
$agent_id = $data['agent_id']->user_id;
$name = User::where('id', $user_id)->first()->first_name . ' ' . User::where('id', $user_id)->first()->last_name;
$email = User::where('id', $user_id)->first()->email;
$phone = Agent::where('user_id', $user_id)->first()->phone;
$amount = Input::get('amount');
$details = Input::get('details');
$data = array('details' => $name, 'ip_address' => $_SERVER['REMOTE_ADDR'], 'amount' => $amount, 'payment_status' => 0, 'my_booking' => 2);
$reserv_id = Payment::create($data);
$data_tab_HSBC_payment = array('currency' => 'USD');
$tab_HSBC_payment_id = HsbcPayment::create($data_tab_HSBC_payment);
$stamp = strtotime("now");
$payment_id = Payment::orderBy('created_at', 'desc')->first()->id;
$orderid = "{$stamp}" . 'AP' . "{$payment_id}";
$last_res_resid = str_replace(".", "", $orderid);
$hsbc_id = HsbcPayment::orderBy('created_at', 'desc')->first()->id;
$hsbc_payment_id_pre = "{$stamp}" . 'HSBC' . "{$hsbc_id}";
$hsbc_payment_id = str_replace(".", "", $hsbc_payment_id_pre);
if ($last_res_resid) {
$payment = DB::table('payments')->where('id', $payment_id)->update(array('reference_number' => $last_res_resid, 'HSBC_payment_id' => $hsbc_payment_id));
$data_tab_HSBC_payment = DB::table('hsbc_payments')->where('id', $hsbc_id)->update(array('HSBC_payment_id' => $hsbc_payment_id));
$client = array('booking_name' => $name, 'email' => $email, 'phone' => $phone, 'remarks' => $details, 'val' => 0, 'payment_reference_number' => $last_res_resid);
$client_payment_id = Booking::create($client);
}
$currency = 'USD';
$x = $amount * 1.037;
$total_price_all_hsbc = round($x, 2) * 100;
//dd($hsbc_payment_id . '/' . $currency . '/' . $total_price_all_hsbc . '/' . $last_res_resid);
HsbcPayment::goto_hsbc_gateway($hsbc_payment_id, $currency, $total_price_all_hsbc, $last_res_resid);
// return $this->storeAllDataAndSendEmails();
}
//Payment::create($data);
return Redirect::route('accounts.payments.index');
}
示例13: rules
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$rules = ['name' => 'required', 'email' => 'required|email|unique:users', 'role' => 'required', 'password' => 'required'];
if ($this->isMethod('PATCH')) {
if (!\Entrust::hasRole('admin')) {
unset($rules['role']);
}
$rules['email'] = 'required|email|unique:users,email,' . $this->get('id');
if (empty($this->get('password'))) {
unset($rules['password']);
}
}
return $rules;
}
示例14: destroy
public function destroy(Attachment $attachment)
{
if (!Helper::getMode()) {
return redirect()->back()->withErrors(config('constants.DISABLE_MESSAGE'));
}
if ($attachment->user_id != Auth::user()->id && !Entrust::hasRole('admin')) {
return redirect()->back()->withErrors(config('constants.INVALID_LINK'));
}
$belongs_to = $attachment->belongs_to;
File::delete('uploads/attachment_files/' . $attachment->file);
$attachment->delete($id);
$activity = 'Deleted a file on a ' . $belongs_to;
Activity::log($activity);
return redirect()->back()->withSuccess(config('constants.DELETED'));
}
示例15: update
public function update($id, $userData)
{
if (isset($userData['password']) && !empty(trim($userData['password']))) {
$userData['password'] = bcrypt($userData['password']);
} else {
unset($userData['password']);
}
$user = $this->user->find($id);
$user->update($userData);
if (\Entrust::hasRole('admin')) {
$role = $this->role->where('name', $userData['role'])->first();
$user->roles()->detach();
$user->attachRole($role);
}
}