本文整理汇总了PHP中User::first方法的典型用法代码示例。如果您正苦于以下问题:PHP User::first方法的具体用法?PHP User::first怎么用?PHP User::first使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类User
的用法示例。
在下文中一共展示了User::first方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($options = array())
{
parent::__construct($options);
// connect to database
$database = Registry::get("database");
$database->connect();
// schedule: load user from session
Events::add("framework.router.beforehooks.before", function ($name, $parameters) {
$session = Registry::get("session");
$controller = Registry::get("controller");
$user = $session->get("user");
if ($user) {
$controller->user = \User::first(array("id = ?" => $user));
}
});
// schedule: save user to session
Events::add("framework.router.afterhooks.after", function ($name, $parameters) {
$session = Registry::get("session");
$controller = Registry::get("controller");
if ($controller->user) {
$session->set("user", $controller->user->id);
}
});
// schedule: disconnect from database
Events::add("framework.controller.destruct.after", function ($name) {
$database = Registry::get("database");
$database->disconnect();
});
}
示例2: run
public function run()
{
DB::table('comments')->delete();
$user_id = User::first()->id;
$post_id = Post::first()->id;
DB::table('comments')->insert(array(array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content1), array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content2), array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content3), array('user_id' => $user_id, 'post_id' => $post_id + 1, 'content' => $this->content1), array('user_id' => $user_id, 'post_id' => $post_id + 1, 'content' => $this->content2), array('user_id' => $user_id, 'post_id' => $post_id + 2, 'content' => $this->content1)));
}
示例3: do_help
public function do_help()
{
$user = Sentry::getUser();
$subject = "Newsletter Help: " . Input::get('subject');
$emailbody = Input::get('message');
$from_name = $user->first_name . ' ' . $user->last_name;
$from_email = $user->email;
$admin = User::first();
$to_name = $admin->first_name . ' ' . $admin->last_name;
$to_email = $admin->email;
$rules = array('subject' => 'required|max:128', 'message' => 'required');
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to('dashboard/help')->withErrors($validator);
} else {
$browser = new Browser();
$userbrowser = $browser->getBrowser() . ' ' . $browser->getVersion();
$userplatform = $browser->getPlatform();
$userIP = $_SERVER["REMOTE_ADDR"];
$page = URL::current();
$data = array('emailbody' => $emailbody, 'userbrowser' => $userbrowser, 'userplatform' => $userplatform, 'userIP' => $userIP, 'page' => $page);
$issent = Mail::send('emails.help-email', $data, function ($message) use($from_email, $from_name, $subject, $to_name, $to_email) {
$message->from($from_email, $from_name)->to($to_email, $to_name)->subject($subject);
});
if ($issent) {
return Redirect::to('dashboard/help')->with('success', 'Success! You will be contacted soon regarding your issue.');
} else {
return Redirect::to('dashboard/help')->with('error', 'An error was encountered sending the email. Please try again.');
}
}
}
示例4: run
public function run()
{
DB::table('comments')->delete();
$user_id = User::first()->id;
$post_id = Post::first()->id;
DB::table('comments')->insert(array(array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content1, 'created_at' => new DateTime(), 'updated_at' => new DateTime()), array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content2, 'created_at' => new DateTime(), 'updated_at' => new DateTime()), array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content3, 'created_at' => new DateTime(), 'updated_at' => new DateTime()), array('user_id' => $user_id, 'post_id' => $post_id + 1, 'content' => $this->content1, 'created_at' => new DateTime(), 'updated_at' => new DateTime()), array('user_id' => $user_id, 'post_id' => $post_id + 1, 'content' => $this->content2, 'created_at' => new DateTime(), 'updated_at' => new DateTime()), array('user_id' => $user_id, 'post_id' => $post_id + 2, 'content' => $this->content1, 'created_at' => new DateTime(), 'updated_at' => new DateTime())));
}
示例5: initTestStep
/**
* Initializes the test step by enabling filters
*
* @param bool $enableFilters
* @return void
*/
protected function initTestStep($enableFilters = TRUE)
{
$this->be(User::first());
if ($enableFilters) {
Route::enableFilters();
}
}
示例6: login
public function login()
{
if (RequestMethods::post('login')) {
$email = RequestMethods::post('email');
$password = RequestMethods::post('password');
$view = $this->getActionView();
$error = false;
if (empty($email)) {
$view->set('email_error', 'Email is not provided');
$error = true;
}
if (empty($password)) {
$view->set('password_error', 'Password is not provided');
$error = true;
}
if (!$error) {
$user = User::first(array('email=?' => $email, 'password=?' => $password, 'live=?' => true, 'deleted=?' => false));
if (!empty($user)) {
$session = Registry::get('session');
$session->set('user', serialize($user));
header("Location: /users/profile.html");
exit;
} else {
$view->set('password_error', 'Email address and/or password are incorrect');
}
exit;
}
}
}
示例7: fbLogin
public function fbLogin()
{
$this->JSONview();
$view = $this->getActionView();
$session = Registry::get("session");
if (RequestMethods::post("action") == "fbLogin" && isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
// process the registration
$fbid = RequestMethods::post("fbid");
$access_token = RequestMethods::post("access_token");
$user = !$this->user ? User::first(["fbid = ?" => $fbid]) : $this->user;
if (!$user) {
try {
$user = $this->_register();
} catch (\Exception $e) {
$view->set("success", false);
return;
}
}
$this->setUser($user);
$redirect = RequestMethods::post("loc", "");
if ($redirect != '') {
$token = Shared\Markup::uniqueString();
$session->set('CampaignAccessToken', $token);
$view->set("redirect", "/" . $redirect . "/{$token}");
}
$view->set("success", true);
} else {
$view->set("success", false);
}
}
示例8: run
public function run()
{
DB::table('posts')->delete();
$user_id = User::first()->id;
Post::create(array('user_id' => $user_id, 'title' => 'Lorem ipsum dolor sit amet', 'slug' => 'lorem-ipsum-dolor-sit-amet', 'content' => $this->content, 'meta_title' => 'meta_title1', 'meta_description' => 'meta_description1', 'meta_keywords' => 'meta_keywords1', 'created_at' => new DateTime(), 'updated_at' => new DateTime()));
Post::create(array('user_id' => $user_id, 'title' => 'Vivendo suscipiantur vim te vix', 'slug' => 'vivendo-suscipiantur-vim-te-vix', 'content' => $this->content, 'meta_title' => 'meta_title2', 'meta_description' => 'meta_description2', 'meta_keywords' => 'meta_keywords2', 'created_at' => new DateTime(), 'updated_at' => new DateTime()));
Post::create(array('user_id' => $user_id, 'title' => 'In iisque similique reprimique eum', 'slug' => 'in-iisque-similique-reprimique-eum', 'content' => $this->content, 'meta_title' => 'meta_title3', 'meta_description' => 'meta_description3', 'meta_keywords' => 'meta_keywords3', 'created_at' => new DateTime(), 'updated_at' => new DateTime()));
}
示例9: setUp
public function setUp()
{
parent::setUp();
// Authentication as super user.
$user = User::first();
Auth::login($user);
$this->createLRS();
}
示例10: testDelete
/**
* Tests the update function in the MetricController
* @depends testStore
* @param void
* @return void
*/
public function testDelete()
{
$this->be(User::first());
$this->runStore($this->input);
$metric = new MetricController();
$metric->delete(1);
$metricDeleted = Metric::withTrashed()->find(1);
$this->assertNotNull($metricDeleted->deleted_at);
}
示例11: testDelete
/**
* Tests the update function in the TopUpController
* @depends testStore
* @param void
* @return void
*/
public function testDelete()
{
$this->be(User::first());
$this->runStore($this->input);
$topup = new TopUpController();
$topup->delete(1);
$topupDeleted = TopUpRequest::withTrashed()->find(1);
$this->assertNotNull($topupDeleted->deleted_at);
}
示例12: testDelete
/**
* Tests the update function in the CommodityController
* @depends testStore
* @param void
* @return void
*/
public function testDelete()
{
$this->be(User::first());
$this->runStore($this->input);
$commodity = new CommodityController();
$commodity->delete(1);
$commodityDeleted = Commodity::withTrashed()->find(1);
$this->assertNotNull($commodityDeleted->deleted_at);
}
示例13: testDelete
/**
* Tests the update function in the IssueController
* @depends testStore
* @param void
* @return void
*/
public function testDelete()
{
$this->be(User::first());
$this->runStore($this->input);
$issue = new IssueController();
$issue->delete(1);
$issueDeleted = Issue::withTrashed()->find(1);
$this->assertNotNull($issueDeleted->deleted_at);
}
示例14: testUpdateFails
public function testUpdateFails()
{
Factory::create('User', ['first_name' => 'foo']);
$user = User::first();
$this->action('PUT', 'Admin\\UsersController@update', $user->id, ['first_name' => null]);
$this->assertRedirectedToRoute('admin.users.edit', $user->id);
$this->assertHasOldInput();
$this->assertSessionHasErrors();
}
示例15: testDelete
/**
* Tests the update function in the SupplierController
* @depends testStore
* @param void
* @return void
*/
public function testDelete()
{
$this->be(User::first());
$this->runStore($this->input);
$supplier = new SupplierController();
$supplier->delete(1);
$supplierDeleted = Supplier::withTrashed()->find(1);
$this->assertNotNull($supplierDeleted->deleted_at);
}