1. Go to this page and download the library: Download darrylkuhn/enforce library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
class User extends Eloquent
{
public static function enforceOnRead( $models )
{
// If the user is not logged in then they can't read user data period
if ( !Auth::check() )
{
return null;
}
// Filter out any results that don't belong to the user
else
{
$key = 'id';
$refrenceValue = Auth::user()->id;
return self::enforceFilter($models, $key, $refrenceValue);
}
}
}
class User extends Eloquent
{
public static function enforceOnRead( $models )
{
// If the user is not logged in then they can't read user data period
if ( !Auth::check() )
{
return null;
}
// If our user isn't an admin then we need to be sure to
// filter out any results that aren't theirs
elseif ( ! Auth::user()->isAdmin() )
{
$key = 'id';
$refrenceValue = Auth::user()->id;
return self::enforceFilter($models, $key, $refrenceValue);
}
// Otherwise they can see anything.
else
{
return $models;
}
}
}
Route::filter('app.applyEnforce', function()
{
// Make sure our models enforce their access rules by default from here on out
Config::set('enforce.byDefault', true);
});