/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { return view('admin.advert.index')->with(['adverts' => Advert::all()]); }
/** * Display a listing of the resource. * * @return Response */ public function index() { return view('adverts', ['adverts' => Advert::all()]); }
/** * Gets an array of all the allowed averts the specified user is able * to access and modify because they're admin * @param User $user * @param array $allowed_departments * @return EloquentCollection */ public function getAllowedAdverts($user, $allowed_departments) { // Check if super or admin if ($user->is_super_user) { return Advert::all(); // Return all adverts } else { $adverts = collect([]); // Get every user assigned to every department // this admin is responsible for foreach ($allowed_departments as $department) { $departmentAdverts = $department->Adverts()->get(); if ($departmentAdverts->count() > 0) { $adverts = $adverts->merge($departmentAdverts); } } } // Only return unqiue users return $adverts->unique('id'); }