根据用户角色,同一URL如何指向不同的控制器?
例如,如果用户具有管理员角色,则#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cassert>
class CSV_t
{
typedef std::vector<int> IntVec_t;
// private nested class -- holds contents of 1 csv record
class CSVRec_t
{
public:
std::string primary;
std::string secondary;
std::string nullary;
std::string thirdary;
IntVec_t i5;
std::string show()
{
std::stringstream ss;
ss << std::setw(25) << primary
<< " " << std::setw(10) << secondary
<< " " << std::setw(12)<< thirdary << " ";
for (size_t i=0;
i<i5.size(); ++i) ss << std::setw(5) << i5[i];
ss << std::endl;
return (ss.str());
}
}; // class CSVRec_t
typedef std::vector<CSVRec_t> CSVRecVec_t;
CSVRecVec_t csvRecVec; // holds all csv record
public:
CSV_t() { };
void init(std::istream& ss)
{
do // read all rows of file
{
CSVRec_t csvRec;
std::string s;
(void)std::getline(ss, s);
if(0 == s.size()) break;
assert(s.size()); extractQuotedField(s, csvRec.primary); // 1st quoted substring
assert(s.size()); extractQuotedField(s, csvRec.secondary); // 2nd quoted substring
assert(s.size()); confirmEmptyField(s, csvRec.nullary); // null field
assert(s.size()); extractQuotedField(s, csvRec.thirdary); // 3rd quoted substring
assert(s.size()); extract5ints(s, csvRec.i5); // handle 5 int fields
csvRecVec.push_back(csvRec); // capture
if(ss.eof()) break;
}while(1);
}
void show()
{
std::cout << std::endl;
for (size_t i = 0; i < csvRecVec.size(); ++i)
std::cout << std::setw(5) << i+1 << " " << csvRecVec[i].show();
std::cout << std::endl;
}
private:
void extractQuotedField(std::string& s, std::string& s2)
{
size_t indx1 = s.find('"', 0);
assert(indx1 != std::string::npos);
size_t indx2 = s.find('"', indx1+1);
assert(indx2 != std::string::npos);
size_t rng1 = indx2 - indx1 + 1;
s2 = s.substr(indx1, rng1);
s.erase(indx1, rng1+1);
}
void confirmEmptyField(std::string& s, std::string nullary)
{
size_t indx1 = s.find('"');
nullary = s.substr(0, indx1);
// tbd - confirm only spaces and comma's in this substr()
s.erase(0, indx1);
}
void extract5ints(std::string& s, IntVec_t& i5)
{
std::stringstream ss(s);
int t = 0;
for (int i=0; i<5; ++i)
{
ss >> t;
ss.ignore(1); // skip ','
assert(!ss.bad()); // confirm ok
i5.push_back(t);
}
s.erase(0, std::string::npos);
}
}; // class CSV_t
int t288(void) // test 288
{
std::stringstream ss;
ss << "\"Primary, Secondary, Third\", \"Primary\", , \"Secondary\", 18, 4, 0, 0, 0\n"
<< "\"Pramiry, Secandory, Thrid\", \"Pramiry\", , \"Secandory\", 19, 5, 1, 1, 1\n"
<< "\"Pri-mary, Sec-ondary, Trd\", \"Pri-mary\", , \"Sec-ondary\", 20, 6, 2, 3, 4\n"
<< std::endl;
CSV_t csv;
csv.init(ss);
csv.show(); // results
return (0);
}
应该/route1
,如果用户具有Admin\route1Controller@index
角色,则应OtherRole\route1Controller@index
。
如何做到这一点?
答案 0 :(得分:0)
您可以通过在laravel中使用roman bican角色包创建角色,在routes.php文件中使用中间件来实现它。
答案 1 :(得分:0)
试试这个:
您可以重定向同一控制器中的所有用户。但是从控制器,根据用户类型,您可以在不同的页面中重定向。