Skip to content

Instantly share code, notes, and snippets.

@flackend
Created June 27, 2015 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flackend/117886bfbc7df988364e to your computer and use it in GitHub Desktop.
Save flackend/117886bfbc7df988364e to your computer and use it in GitHub Desktop.
<ul>
@foreach ($user in $users)
<li>{{ $user->name }} has a level of {{ $user->level }}</li>
@endforeach
</ul>
<?php
public function index()
{
$users = User::all();
$level = $this->showLevel('test');
return view('home')->with('users', $users);
}
<?php
class User extends Eloquent {
public function getLevelAttribute() {
$level = $this->attributes['exp'];
if ($level < 500) {
return 1;
} else if ($level > 500 && $level < 1000) {
return 2;
} else if ($level > 1000 && $level < 1500) {
return 3;
} else if ($level > 1500 && $level < 2000) {
return 4;
} else if ($level > 2000 && $level < 2500) {
return 5;
} else if ($level > 2500) {
return 'MAX';
}
}
}
@flackend
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment