Laravel 5.4 "format" model output
Go to solution
Solved by leodaniel,
I am not familiar with blade because I always use twig as my templating engine. You may be searching for a filter right?
Anyway, I am not completely sure what you are asking.
If I understand it right:
/* Gather your model */
$users = App\User::all();
foreach($users as $user){
/*Do Your Stuff here*/
}
If it's just displaying your results use a filter in blade (I think they exist in blade). If you want to format your result from the DB for usage in you app, you can use a Model Access Mutator. Check the Laravel Documentation for that.
If you just want to format say like the name (column: name) you can use an access Mutator on your Model
/* in App\User */
public function getNameAttribute($name){
return 'Name: '.$name;
}
/* now when you access the name */
$user = App\User::find(1);
echo user->name;
/* will output: Name: YourUserName */

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now