{{Auth::admin()->name}} this gives error, how will i retrieve the current admin name from the database using blade.
I'm getting this error, Method Illuminate\Auth\SessionGuard::admin does not exist.
This works. {{ auth('admin')->user()->name }}
Related
Trying to show the current signed in user's profile. What am i doing wrong.This is the function on the controller. I'm using Laravel 9
public function show(User $user)
{
return view('users.index', with('user', $user));
}
This is the routes
Route::resource('users', UsersController::class)->middleware('auth');
And my generic layout page
<x-dropdown-item href="/users/{{ auth()->user()->username }}" >Account</x-dropdown-item>
When i click the link i get user not found.
You're utilising route model binding which unless configured otherwise, requires you to provide a route with a model id. You're providing it with a username, so Laravel is throwing a 404 because it can't locate the relevant record in the database.
If you replace username with id, the binding should work.
<x-dropdown-item href="/users/{{ auth()->user()->id }}">
Account
</x-dropdown-item>
The code is fine. Are you sure you have a route with username, resource routes are using id.
To access model like that you need to specify id in the route like:
/users/{id}
However what you are trying to do here is access the logged in user model which you can access with the facade Auth::user();
You can access the user any time any where in the code and there is no need to pass it to an anchor link unless sending to an external system.
I installed the spatie to Laravel permission:
but when I tried to check if the user has rule , this problem appears:
Call to a member function contains() on null?
my code is:
#role('Admin')
<p>This message appears if the user is an admin </p>
#endrole
note: if I check using permission like this:
#can('show-post')
<p>This message appears if the user is an admin </p>
#endcan
it work, why using role doesn't work?
After upgrade to 5.4 we have a problem with the Notifiy mailables, we embed the Application logo via
{{ $message->embed($path) }}
and it doesnt work anymore, i have a 5.3 copy where it works.. it looks like the $message variable is not injected automaticly anymore. we tried without the embedded image and the mailview is working.
Is there anything missing during our upgrade? i checked the upgradeguide twice.. we not using markdown.
Error:
Undefined variable: message (View: W:\project\resources\views\vendor\notifications\email.blade.php)
Codeexample:
User::find(1)->notify(
new EmailCredentialsTest(User::find(1))
);
I'm checking out Laravel docs for Maintenance Mode:
https://laravel.com/docs/5.3/configuration#maintenance-mode
When you execute the command php artisan down, it will put the application under maintenance mode, and return the 503.blade.php view.
Works good, but there is an option I can't really make work.. when I do:
php artisan down --message='Upgrading Database' --retry=60
I want to display the message in the view, I tried accessing the obvious choice with {{ $message }} without success, returns undefined variable.
My question is: how to access it?
Actually you don't need that "json_decode" stuff, as all the "error" views (including 503.blade.php) have $exception variable.
So you may just use {{ $exception->getMessage() }} in your view and you will get the exact value that you have passed to artisan down --message command.
By default 503.blade.php view doesn't use this message.
This message is available in a JSON formatted file named storage/framework/down generated by php artisan down command.
You could do something like this to access the directly the message in your view:
{{ json_decode(file_get_contents(storage_path('framework/down')), true)['message'] }}
A cleaner way is to use the $exception variable and include in your view {{ $exception->getMessage() }} like suggested in this answer.
Under the hood, the CheckForMaintanceMode middleware reads the message and other data from the file and thrown a MaintanceModeException with this data.
Edit: After Laravel 8, the payload that creates the storage/framework/down command has changed and doesn't include the exception message. You should use the {{ $exception->getMessage() }} instead on Laravel 8+.
If you want detailed information (not just message) on your maintenance page, you can also use $exception->retryAfter(Int), $e->willBeAvailableAt(Carbon) and $e->wentDownAt(Carbon).
Of course you need to set --retry parameter in artisan command.
I am using the Laravel 5 ResetsPasswords trait to implement password reset. In the file resources/views/emails/password.blade.php., I have the following code.
Click To Reset Password
I am using a queue to send the email to the user. When the user clicks the link received in email, I get something like below:
http://localhost/password/reset/2aafe5381baa67f9d1fe2f476c0f1395b21e71fafe181b2980fb838fc9e0b2fc
I was rather expecting:
http://localhost/oap/public/password/reset/2aafe5381baa67f9d1fe2f476c0f1395b21e71fafe181b2980fb838fc9e0b2fc
Why is oap/public/ not in the url? I have used the url() function in other views and they have worked just well except for this email view where I am using queue to send the message. When a queue is not used to send the message, the link is okay. Any idea how I can resolve this issue.
Use URL::to. Like,
Click To Reset Password
for the url helpers it will generate the full path for your inputs
{{ url('/password/reset/'.$token) }}
will generate
http://localhost/password/reset/2aafe5381baa67f9d1fe2f476c0f1395b21e71fafe181b2980fb838fc9e0b2fc
and
{{ url('/oap/public/password/reset/'.$token) }}
will generate
http://localhost/oap/public/password/reset/2aafe5381baa67f9d1fe2f476c0f1395b21e71fafe181b2980fb838fc9e0b2fc
you can also get around this
Route::get('oap/public/password/reset/{confirmcode}', ['as' => 'resetpassword', 'HomeController#resetmethod']);
then using this like that
{{route('resetpassword', ['confirmcode' => $token])}}