Hidden Features of PHP?
Documentation. The documentation gets my vote. I haven't encountered a more thorough online documentation for a programming language everything else I have to piece together from various websites and man pages.
Laravel: Why is Eloquent displaying hidden fields?
That's because these fields are only hidden when you convert your model to array or JSON.
From the documentation:
Sometimes you may wish to limit the attributes, such as passwords, that are included in your model's array or JSON representation.
The whole documentation about this topic is available here: https://laravel.com/docs/8.x/eloquent-serialization#hiding-attributes-from-json
The goal is to remove them from your API responses.
However, you might still use them when you are working with your models in controllers, services... that's why you see them.
You can check it works by doing:
$user = User::first();
$user->toArray(); // hidden attributes not included
$user->toJson(); // hidden attributes not included
Restrict some site features for members
Just to illustrate, on your index.php
page, or whatever page, for testing, paste this code at the very top and use the links to toggle between sessions:
<?php session_start(); ?>
<a href="?admin=1">Admin User</a>
<a href="?admin=0">Not Admin</a>
<a href="?admin=base">Not logged in</a>
<?php
if(isset($_GET['admin']) && $_GET['admin'] == 1)
$_SESSION['admin'] = true;
elseif(isset($_GET['admin']) && $_GET['admin'] == 0)
$_SESSION['admin'] = false;
if(isset($_GET['admin']) && $_GET['admin'] == 'base')
if(isset($_SESSION['admin'])) unset($_SESSION['admin']);
if(isset($_SESSION['admin']) && $_SESSION['admin'] == true) { ?>
<p>You are admin and this is your image</p>
<img src="http://s.hswstatic.com/gif/african-tree-frog.jpg" />
<?php } elseif(isset($_SESSION['admin']) && $_SESSION['admin'] == false) { ?>
<p>You are NOT admin but logged in. This is your image.</p>
<img src="http://news.nationalgeographic.com/news/2005/10/images/051007_robot_fish.jpg" />
<?php }
if(!isset($_SESSION['admin'])) { ?>
<h2>You are not logged in!</h2>
<?php } ?>
<p>This is a site about animals. Everyone can read this.</p>
<?php session_destroy(); ?>
hide feature toggle in production mode
Wrapped the Toggle in #if DEBUG
#if DEBUG
Toggle(isOn: .constant(true), label: {
Text("Label")
})
#endif
Related Topics
Using Square Brackets in Hidden HTML Input Fields
How to Throttle My Site's API Users
Verify Imagemagick Installation
Why and How to Use Anonymous Functions in PHP
How to Solve General Error: 2006 MySQL Server Has Gone Away
Parse Error: Invalid Numeric Literal
Remove Item from Array If It Exists in a 'Disallowed Words' Array
Parametrized Pdo Query and 'Limit' Clause - Not Working
Composer Killed While Updating
Calling a Particular PHP Function on Form Submit
Type Casting for User Defined Objects
How to Pass an Array via $_Get in PHP
Convert an Associative Array to a Simple Array of Its Values in PHP
How to Send a Status Code in PHP, Without Maintaining an Array of Status Names