public function index()
 {
     $players = Player::where('first_name', 'LIKE', '%' . Input::get('q') . '%')->orWhere('last_name', 'LIKE', '%' . Input::get('q') . '%')->orWhereHas('guardian', function ($q) {
         $q->where('users.first_name', 'LIKE', '%' . Input::get('q') . '%')->orWhere('users.last_name', 'LIKE', '%' . Input::get('q') . '%')->orWhere('email', 'LIKE', '%' . Input::get('q') . '%');
     })->with('guardian')->orderBy('last_name', 'ASC')->orderBy('first_name', 'ASC')->paginate(25);
     return view('/admin/players/index', ['players' => $players->appends(Input::only('q'))]);
 }
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     return Player::where('id', $this->route('player'))->where('guardian_id', Auth::user()->id)->count() > 0;
 }
Exemple #3
0
 public static function validationRules()
 {
     // check to see if the current user already has a player with this same name
     // Admins can add duplicate players, but parents can't
     Validator::extend('guardian_isnt_duplicate_player', function ($attribute, $value, $parameters, $validator) {
         $data = $validator->getData();
         $conditions = ['guardian_id' => Auth::user()->id, 'first_name' => $data['first_name'], 'last_name' => $data['last_name']];
         return Player::where($conditions)->count() == 0;
     });
     return ['first_name' => 'required|max:32', 'last_name' => 'required|max:32', 'gender' => 'required', 'birthday' => 'required|date'];
 }