In my sessions I have added some things OK and can show them OK, however I added the user info as an array
session()->put('userinfo',Auth::user());
but I cannot seem to recall for display or use on of the userino items, name.
What is the syntax?
Found the solution:
{{ session()->get('userinfo')->name }}
Related
Im trying to show some data in my view and ONLY the id property is getting changed to some random number when its passed to the view. The other properties are okay.
If I try to access a property from a view like this: {{ dd($var[1]) }}, it works and I can see the id like this:
But if I try to access passing the id directly: {{ dd($var[1]['id']) }} or {{ dd($var[1]->id) }}, I just get this:
And here are some more examples from what I get accessing it directly:
If I use gettype() is this var I get Integer back, but it is actually a string as you can see in the first printscreen.
Why is my blade view doing this? And how can I fix it?
I ended up using another id I was receiving in the same array, looks like blade was decoding the string or something like that. Thanks for the answers.
in your controller please select id as new_id and try to print
$var[1]->new_id or $var[1]['new_id']
it will fix your problem
if fixed give a green tick and a thumbs up else leave a commetn will try to update you
Wondering if it is possible to manipulate the output of a #yield in Laravel? In short I have a title in my child template that I would like to set some id's with to make them unique. I know I could just create another #section('id', 'asdf') but rather not have to worry users with that especially since the title has to be unique anyways...
Could not find anything that says this is possible?
Example (which fails) but what I am essentially trying to do:
id="{{Str::kebab(#yield('title'))}}-preview-tab"
#yield gets replaced with a PHP echo statement so that is not what you want. If you want the content of a section you can grab it from the View Factory:
$__env->getSection($name, $default)
Or even calling yieldContent:
$__env->yieldContent($section, $default)
So you could try:
{{ Str::kebab($__env->getSection('title', 'some default if you want')) }}
If you have any issues with that, try the yieldContent method.
whats the best or the usual way to remove all roles from a user?
I tried
$roles = $user->getRoleNames(); $user->removeRole($roles);
Return value of App\User::getStoredRole() must implement interface Spatie\Permission\Contracts\Role, instance of Illuminate\Support\Collection returned
Use the plain Laravel detach method like so:
$user->roles()->detach();
I dod it now in this way $user->removeRole($user->roles->first());
You can also remove all roles by syncing to an empty array, like so.
$user->syncRoles([]);
I confirmed it works on version 5.8.
From reading the documentation it clearly says that you can pass a Collection instance to the removeRole so I think you are doing it right.
The assignRole, hasRole, hasAnyRole, hasAllRoles and removeRole functions can accept a string, a \Spatie\Permission\Models\Role object or an \Illuminate\Support\Collection object.
This works fine even on Laravel 7
For Roles:
$user->syncRoles([]);
For Permissions:
$user->syncPermissions([]);
From Spatie documentation you can find ther is a way to remove all previous roles and assign new roles with simple
$user->syncRoles($roles);
For reference you can visit this link
I am using Symfony 2.3.
I have created simple order form using $this->createFormBuilder in my controller. I am validating one Doctrine field with:
/**
* #Assert\Length(min=3)
*/
protected $name;
However, upon validation fail, I get a duplicated error message near the field:
This value is too short. It should have 3 character or more.|This value is too short. It should have 3 characters or more.
My template for this element is as simple as:
{{ form_errors(form.name) }}
{{ form_label(form.name) }}
{{ form_widget(form.name) }}
Everything else seems to bet working as expected, except for that validation error message being duplicated. As if pluralization would not be working. Anyone has a suggestion on why this would be failing?
EDIT
It seems that SonataAdminBundle is overriding form_errors block. How to remove that override from non-sonata controller?
Maybe the sonata's template is not in sync with the latest changes from the original template.
Can you create a PR or an issue on github, thanks
The problem was that I had set this in my config.yml:
# Twig Configuration
twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%
form:
resources:
- 'SonataAdminBundle:Form:silex_form_div_layout.html.twig'
- 'SonataFormatterBundle:Form:formatter.html.twig'
The silex_form_div_layout.html.twig one overrides form_errors Twig block, and removing it fixes the problem.
I'm having an issue with the Laravel 4 Package Former and the use of checkboxes. I'm trying to Former::populate() a user edit form within a blade template but my checkboxes are always checked.
Here is my current code:
{{ Former::checkbox('is_admin')->text('Is Admin?'); }}
I've tried:
{{ Former::checkbox('is_admin')->text('Is Admin?')->check(false); }}
and
{{ Former::checkbox('is_admin')->text('Is Admin?')->forceValue(false); }}
To no avail.
My database field 'is_admin' is a boolean field. I thought maybe Former didn't like 1s and 0s but it doesn't uncheck my checkboxes even if I set a getter to return false.
Any Ideas?
Thanks
Sounds like a bug with Former.. Keep in mind it looks like you can overrule whatever happened with populate with populateField.