本文整理汇总了PHP中Auth::id方法的典型用法代码示例。如果您正苦于以下问题:PHP Auth::id方法的具体用法?PHP Auth::id怎么用?PHP Auth::id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Auth
的用法示例。
在下文中一共展示了Auth::id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Confirm
/**
*
*/
public function Confirm()
{
$auth = new Auth();
$shop = new ShoppingCart();
$user = $auth->id();
$myShop = $shop->all();
$objDetails = new DetalleCompra();
$total = 0;
if (empty($myShop)) {
return false;
}
foreach ($myShop as $key => $val) {
$total += $val->precio * $val->cantidad;
}
$result_insert = $this->create($user, $total);
if ($result_insert->success) {
foreach ($myShop as $k => $v) {
try {
$objDetails->create($result_insert->id, $v->id_prod, $v->name, $v->cantidad, $v->precio, $v->talle, $v->color);
//$stock = new TempStock();
//echo $stock->removeTempStock($user,$v->id_prod,$v->id_talle,$v->id_color,$v->type);
} catch (Exception $e) {
echo $e->getMessage();
}
}
$auth->restPoints($total);
$auth->sumConsumed($total);
$shop->removeAll();
return true;
}
}
示例2: viewresult
public function viewresult()
{
echo "hello";
exit;
$user_id = \Auth::id();
return view('user.view_result');
}
示例3: destroy
/**
* Unfollow a user
*
* @param $userIdToUnfollow
* @return Response
*/
public function destroy($userIdToUnfollow)
{
$input = array_add(Input::all(), 'userId', Auth::id());
$this->execute(UnfollowUserCommand::class, $input);
Flash::success("You have now unfollowed this user.");
return Redirect::back();
}
示例4: postLogin
public function postLogin()
{
if (Request::ajax()) {
$userdata = array('usuario' => Input::get('usuario'), 'password' => Input::get('password'));
if (Auth::attempt($userdata, Input::get('remember', 0))) {
//buscar los permisos de este usuario y guardarlos en sesion
$query = "SELECT m.nombre as modulo, s.nombre as submodulo,\n su.agregar, su.editar, su.eliminar,\n CONCAT(m.path,'.', s.path) as path, m.icon\n FROM modulos m \n JOIN submodulos s ON m.id=s.modulo_id\n JOIN submodulo_usuario su ON s.id=su.submodulo_id\n WHERE su.estado = 1 AND m.estado = 1 AND s.estado = 1\n and su.usuario_id = ?\n ORDER BY m.nombre, s.nombre ";
$res = DB::select($query, array(Auth::id()));
$menu = array();
$accesos = array();
foreach ($res as $data) {
$modulo = $data->modulo;
//$accesos[] = $data->path;
array_push($accesos, $data->path);
if (isset($menu[$modulo])) {
$menu[$modulo][] = $data;
} else {
$menu[$modulo] = array($data);
}
}
$usuario = Usuario::find(Auth::id());
Session::set('language', 'Español');
Session::set('language_id', 'es');
Session::set('menu', $menu);
Session::set('accesos', $accesos);
Session::set('perfilId', $usuario['perfil_id']);
Session::set("s_token", md5(uniqid(mt_rand(), true)));
Lang::setLocale(Session::get('language_id'));
return Response::json(array('rst' => '1', 'estado' => Auth::user()->estado));
} else {
$m = '<strong>Usuario</strong> y/o la <strong>contraseña</strong>';
return Response::json(array('rst' => '2', 'msj' => 'El' . $m . 'son incorrectos.'));
}
}
}
示例5: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$user_id = Auth::id();
$comment = Input::get('comment');
$tags = Input::get('tagged_uid');
$rating = Input::get('rating');
$type = Input::get('media_type');
$imdb_id = Input::get('imdb_id');
$post = new Post();
$post->user_id = $user_id;
$post->type = $type;
$post->imdb_id = $imdb_id;
$post->rating = $rating;
$post->comment = $comment;
$post->save();
if (sizeof($tags) > 0) {
foreach ($tags as $tagged_uid) {
$tag = new Tag();
$tag->post_id = $post->id;
$tag->user_tagging = $user_id;
$tag->user_tagged = $tagged_uid;
$tag->save();
}
}
return Redirect::to('/media/' . $imdb_id);
}
示例6: vote
public function vote()
{
$class = \Input::get('class');
$postId = \Input::get('postId');
$previousVote = PostVote::where('user_id', \Auth::id())->where('post_id', $postId)->first();
$isUpvote = str_contains($class, 'up');
// If there is a vote by the same user on the same post
if (!is_null($previousVote)) {
if ($isUpvote) {
if ($previousVote->type === 'up') {
// Cancel out previous upvote
$previousVote->delete();
} else {
$previousVote->update(['type' => 'up']);
}
} else {
if ($previousVote->type === 'down') {
// Cancel out previous downvote
$previousVote->delete();
} else {
$previousVote->update(['type' => 'down']);
}
}
} else {
// Create a new vote
PostVote::create(['type' => $isUpvote ? 'up' : 'down', 'user_id' => \Auth::id(), 'post_id' => $postId]);
}
}
示例7: store
/**
* Store a newly created resource in storage.
* POST /article
*
* @return Response
*/
public function store()
{
$rules = ['title' => 'required|max:100', 'content' => 'required', 'tags' => array('required', 'regex:/^\\w+$|^(\\w+,)+\\w+$/')];
$validator = Validator::make(Input::all(), $rules);
if ($validator->passes()) {
$article = Article::create(Input::only('title', 'content'));
$article->user_id = Auth::id();
$resolved_content = Markdown::parse(Input::get('content'));
$article->resolved_content = $resolved_content;
$tags = array_unique(explode(',', Input::get('tags')));
if (str_contains($resolved_content, '<p>')) {
$start = strpos($resolved_content, '<p>');
$length = strpos($resolved_content, '</p>') - $start - 3;
$article->summary = substr($resolved_content, $start + 3, $length);
} elseif (str_contains($resolved_content, '</h')) {
$start = strpos($resolved_content, '<h');
$length = strpos($resolved_content, '</h') - $start - 4;
$article->summary = substr($resolved_content, $start + 4, $length);
}
$article->save();
foreach ($tags as $tagName) {
$tag = Tag::whereName($tagName)->first();
if (!$tag) {
$tag = Tag::create(array('name' => $tagName));
}
$tag->count++;
$article->tags()->save($tag);
}
return Redirect::route('article.show', $article->id);
} else {
return Redirect::route('article.create')->withInput()->withErrors($validator);
}
}
示例8: isSeen
public function isSeen()
{
// are there guards?
$game = Auth::user();
$guard = $game->map->guards()->where('health', '>', 0)->where('user_id', Auth::id())->first();
if ($guard) {
// if so
$stealth = $game->stealth;
if ($stealth == 0) {
$stealth = 1;
}
$chance = 5 / $stealth * 100;
$seen = mt_rand(1, 100);
if ($seen < $chance) {
$before = $game->health;
$game->health = $game->health - 1;
$after = $game->health;
if ($game->stealth != 0) {
$game->stealth = $game->stealth - 1;
}
$game->save();
return "You have been spotted and a guard attacks you. -1 Health -1 Stealth";
} else {
return "The guards don't see you, but you might want to hurry.";
}
} else {
return false;
}
}
示例9: index
/**
* @return void
*/
public function index()
{
if ($this->Common->isPosted()) {
$name = $this->request->data['ContactForm']['name'];
$email = $this->request->data['ContactForm']['email'];
$message = $this->request->data['ContactForm']['message'];
$subject = $this->request->data['ContactForm']['subject'];
if (!Auth::id()) {
$this->ContactForm->Behaviors->attach('Tools.Captcha');
}
$this->ContactForm->set($this->request->data);
if ($this->ContactForm->validates()) {
$this->_send($name, $email, $subject, $message);
} else {
$this->Common->flashMessage(__('formContainsErrors'), 'error');
}
} else {
// prepopulate form
$this->request->data['ContactForm'] = $this->request->query;
# try to autofill fields
$user = (array) $this->Session->read('Auth.User');
if (!empty($user['email'])) {
$this->request->data['ContactForm']['email'] = $user['email'];
}
if (!empty($user['username'])) {
$this->request->data['ContactForm']['name'] = $user['username'];
}
}
$this->helpers = array_merge($this->helpers, array('Tools.Captcha'));
}
示例10: UserPermissions
public function UserPermissions()
{
if (Auth::check()) {
$user_id = Auth::id();
$cache_key = "user-" . $user_id . "-permissions";
if (Cache::tags('user-permissions')->has($cache_key)) {
$permission_array = Cache::tags('user-permissions')->get($cache_key);
} else {
if (Auth::user()->is_admin) {
$raw_permission_array = [];
$permission_array = [];
$permission_objects = Permission::all();
$user_permissions = DB::table('permission_user')->where('user_id', '=', $user_id)->get();
foreach ($user_permissions as $user_permission) {
$permission_id = $user_permission->permission_id;
$raw_permission_array[$permission_id] = 1;
}
foreach ($permission_objects as $permission) {
$route_name = $permission->route;
$permission_id = $permission->id;
if (isset($raw_permission_array[$permission_id])) {
$permission_array[$route_name] = $raw_permission_array[$permission_id];
} else {
$permission_array[$route_name] = 0;
}
}
} else {
$permission_array = false;
}
Cache::tags('user-permissions')->put($cache_key, $permission_array, 60);
}
}
return $permission_array;
}
示例11: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$post = new Post();
$post->user_id = Auth::id();
Log::info('This is useful info', Input::all());
return $this->validateAndSave($post);
}
示例12: validateAndSave
/**
* Validate inputs and save to database.
*
* @return Response
*/
protected function validateAndSave($post)
{
$validator = Validator::make(Input::all(), Post::$rules);
if ($validator->fails()) {
Session::flash('errorMessage', 'Validation failed');
return Redirect::back()->withInput()->withErrors($validator);
} else {
$post->title = Input::get('title');
$post->content = Input::get('content');
$post->user_id = Auth::id();
$image = Input::file('image');
if ($image) {
$filename = $image->getClientOriginalName();
$post->image = '/uploaded/' . $filename;
$image->move('uploaded/', $filename);
}
$result = $post->save();
$posttags = Input::has('tuttags') ? Input::get('tuttags') : array();
if (Input::has('addtags')) {
$addtag = Input::get('addtags');
$posttags . push($addtag);
}
$post->tags()->sync($posttags);
$post->save();
if ($result) {
Session::flash('successMessage', 'Great Success!');
return Redirect::action('PostsController@show', $post->slug);
} else {
Session::flash('errorMessage', 'Post was not saved.');
return Redirect::back()->withInput();
}
}
}
示例13: getData
protected function getData()
{
$this->userId = \Auth::id();
$this->routeRoot = head(explode(".", app('router')->currentRouteName()));
$this->id = \Input::get('id') == 'new' ? null : \Input::get('id');
$this->routeEntity = implode("&", app('router')->current()->parameters());
}
示例14: upload
/**
* Upload profile picture
*/
public function upload()
{
$validator = Validator::make(Input::all(), ["propic" => "required|image|mimes:jpg,jpeg,png|max:6000"], ["required" => "Please insert an image"]);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator);
} else {
$user = User::find(Auth::id());
if ($user) {
if ($user->profile_picture) {
File::delete("assets/images/propic/" . $user->profile_picture);
}
$image = Input::file('propic');
$name = $image->getClientOriginalName();
/*$type = $image->getMimeType();
$size = $image->getSize()/1000;*/
$destination = 'assets/images/propic/';
$image->move($destination, $name);
$user->profile_picture = 'assets/images/propic/' . $name;
if ($user->save()) {
return Redirect::back()->with('event', '<p class="alert alert-success"><span class="glyphicon glyphicon-ok"></span> Picture uploaded</p>');
}
return Redirect::back()->with("event", '<p class="alert alert-danger"><span class="glyphicon glyphicon-remove"></span> Error occured. Please try after sometime</p>');
}
}
}
示例15: __construct
public function __construct(IRetailerRepository $retailer)
{
parent::__construct();
$this->adminId = Auth::id();
$this->address = new Address();
$this->retailer = $retailer;
}