I'm working on a project with multiple languages. I have already installed French and English, now I need to add Arabic.
I create a ar.json file with traduction and
I added the arabic to config/app.php as
'locales' => ['fr','en','ar',],
Now, I just need to know how to add the rest of code in my view so that I can add the Arabic language with others
<ul class="navbar-nav mr-auto">
<li class="nav-item dropdown">
<a class="nav-link" href="#" id="navbarDropdownFlag" role="button" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false" title="Français">
<img width="20" height="20" alt="{{ session('locale') }}"
src="{!! asset('images/flags/' . session('locale') . '-flag.png') !!}"/>
</a>
<div id="flags" class="dropdown-menu" aria-labelledby="navbarDropdownFlag">
#foreach(config('app.locales') as $locale)
#if($locale != session('locale'))
<a class="dropdown-item" href="{{ route('language', $locale) }}" title="Anglais">
<img width="20" height="20" alt="{{ session('locale') }}"
src="{!! asset('images/flags/' . $locale . '-flag.png') !!}"/>
</a>
#endif
#endforeach
</div>
</li>
</ul>
You may retrieve lines from language files using the __ helper
function. The __ method accepts the file and key of the translation
string as its first argument. For example, let's retrieve the welcome
translation string from the resources/lang/messages.php language file:
echo __('file.key');
If you are using the Blade templating engine, you may use the {{ }}
syntax to echo the translation string or use the #lang directive:
{{ __('file.key') }}
#lang('file.key')
Docs
Related
Problem
The user with the role "author" doesnt see the HTML inside the #can ... endcan block.
Description
Developing a Laravel package and restrict the navbar accordingly to the roles. But when i try to make a nav element only for a user with the role "author", it doesnt work. When i replace "author" with another role, it works.
Maybe my approach is too complicated and proposals for other approaches are welcome as well as hints, where i have to look for solving the problem.
I have a "standard" setup with three tables. One for users, one for roles and one for role_user relations (as it is described here). The relations in the models are set.
You can find the whole project here.
Thanks in advance.
Code
#can('author')
<li class="nav-item">
<a class="nav-link"
href="{{ route('pages.index') }}">{{ __('limplecms::navigation.pages.overview')}}</a>
</li>
#endcan
#canany(['admin', 'editor'])
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown"
aria-expanded="false">
{{ __('limplecms::navigation.pages')}}
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ route('pages.index') }}">
{{__('limplecms::navigation.pages.overview')}}
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="{{ route('pages.create') }}">
{{__('limplecms::navigation.pages.create')}}
</a>
</div>
</li>
#endcanany
#can('admin')
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown"
aria-expanded="false">
{{ __('limplecms::navigation.user.management')}}
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ route('users.index') }}">
{{__('limplecms::navigation.users.overview')}}
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="{{ route('users.create') }}">
{{__('limplecms::navigation.users.create')}}
</a>
</div>
</li>
#endcan
I have created several pieces of my Laravel 7 application (I'm a newbie trying to learn). I then wanted to add authentication on top of that, so I did:
php artisan ui bootstrap --auth
npm install && npm run dev
After doing so, I have a "login" and a "register" link on the top left-corner of every page of my app. These links are being added by some automated method and are not changing the pages (views - *.blade.php files) that I had created before adding the authentication system.
I'd like to prevent these links from being added automatically. Then I can add my own links to my navigation bar. The problem is I can't figure out how they're being created or added to my views. Can someone help me?
NEVERMIND - I FIGURED IT OUT.
Appearently during the authentication system scaffolding my "layout.blade.php" was modified to include both the "login" and "register" links by the addition of this code just under the <body> tag:
<div class="flex-center position-ref full-height">
#if (Route::has('login'))
<div class="top-right links">
#auth
Home
#else
Login
#if (Route::has('register'))
Register
#endif
#endauth
</div>
#endif
</div>
All I needed to do is remove that code block. Hope this helps someone in the future.
The login links are created on a separate template file (views/layouts/app.blade.php). To remove them you need to customize this file.
This is the part where the header links are created:
<!-- Right Side Of Navbar -->
<ul class="navbar-nav ml-auto">
<!-- Authentication Links -->
#guest
<li class="nav-item">
<a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
</li>
#if (Route::has('register'))
<li class="nav-item">
<a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
</li>
#endif
#else
<li class="nav-item dropdown">
<a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
{{ Auth::user()->name }} <span class="caret"></span>
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
{{ __('Logout') }}
</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
#csrf
</form>
</div>
</li>
#endguest
</ul>
I tried to reach the web page but i get Call to a member function prepare().
what i should to do ?
I'm using laravel and MongoDB.
all codes worked good but i get above error when i updated Laravel from 5.8 to 6
<!-- Authentication Links -->
#guest
<li class="nav-item">
<a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
</li>
#if (Route::has('register'))
<li class="nav-item">
<a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
</li>
#endif
#else
<li class="nav-item dropdown">
<a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
{{ Auth::user()->name }} <span class="caret"></span>
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
{{ __('Logout') }}
</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
#csrf
</form>
</div>
</li>
#endguest
problem is about #guest
in "vendor\laravel\framework\src\Illuminate\Foundation\Auth\User.php"
add "use Jenssegers\Mongodb\Eloquent\Model as Eloquent;"
change the "class User extends Model implements" to "class User extends Eloquent implements"
in each model use add:
"use Jenssegers\Mongodb\Eloquent\Model as Eloquent;"
and after you should extend from this eloquent instead extend Model
I've found an alternative fix.
in vendor\spatie\laravel-permission\src\Models\Permission.php and \Role.php
set this:
<?php
...
use Jenssegers\Mongodb\Auth\User as Authenticatable;
...
class Permission extends Authenticatable implements PermissionContract
{
I hope it helps you ;)
I use Hesto/multi-auth package. The username when I login success default redirect in customer.layout.auth, how can I to redirect in my blade, Example: welcome.blade.php, I can't use {{ Auth::user()->name }} in another blade, it error Trying to get property of non-object . How to fix it, please help me !
AppServiceProvider.php
public function register()
{
//
if ($this->app->environment() == 'local') {
$this->app->register('Hesto\MultiAuth\MultiAuthServiceProvider');
}
}
auth.blade.php
#if (Auth::guest())
<li>Login</li>
<li>Register</li>
#else
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
{{ Auth::user()->name }} <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="{{ url('/customer/logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
Logout
</a>
<form id="logout-form" action="{{ url('/customer/logout') }}" method="POST" style="display: none;">
{{ csrf_field() }}
</form>
</li>
</ul>
</li>
#endif
I had the same problem and I think I found the solution.
You are creating your routes on the web route file.
You need to create your routes inside user route file created by Hesto/multi-auth package.
I don't know if this is the right way of doing it but it worked for me.
How to format Laravel Link with <li> and <span> tags, for an example:
Laravel Link
{{ link_to('home', 'Home') }}
Should have to set like this
<li>
<a href="home">
<i class="icon-text-width"></i>
<span class="menu-text"> Home </span>
</a>
</li>
can someone please help me to create Laravel base link with that html tags, thank you
As far as i know, you can not do that using {{ link_to('home', 'Home') }}. However, instead you can do something like the following:
<li>
<a href="{{ route('home') }}">
<i class="icon-text-width"></i>
<span class="menu-text"> Home </span>
</a>
</li>
or you can use url() helper function.
<li>
<a href="{{ url('/') }}">
<i class="icon-text-width"></i>
<span class="menu-text"> Home </span>
</a>
</li>