I have this controller which is storing the host and url of a video in youtube, vimeo, vevo etc
public function attach()
{
$input = Input::except('_token');
if ( ! Input::get('host') || ! Input::get('url')) {
return Response::json(trans('video::main.fillAllRequiredFields'), 400);
}
}
And in the blade i have this
#foreach ($title->link as $k => $video)
<p><a target="_blank" href="{{ $video->url }}">{{ $video->host }}</a></p>
#endforeach
So as for now the member has to insert both the url and the label of the host..
I want to use a function either in Laravel or knockout.js so when an url is inserted to extract the host and show the host label automatically without been stored in DB. Something like this
#foreach ($title->link as $k => $video)
#if {{$video->url}} contain "youtube.com"
<p><a target="_blank" href="{{ $video->url }}">YouTube</a>
#elseif {{$video->url}} contain "vimeo.com"
<p><a target="_blank" href="{{ $video->url }}">Vimeo</a>
#elseif {{$video->url}} contain "vevo.com"
<p><a target="_blank" href="{{ $video->url }}">Vimeo</a>
#else <p><a target="_blank" href="{{ $video->url }}">Unknown</a>
#endif
#endforeach
Any help is really appreciated
PHP function strpos() allows you to check if the url string has specific host inside it or not. For example like this
#foreach ($title->link as $k => $video)
#if(strpos($video->url, "youtube.com")!==false)
<p><a target="_blank" href="{{ $video->url }}">YouTube</a>
#if(strpos($video->url, "vimeo.com")!==false)
<p><a target="_blank" href="{{ $video->url }}">Vimeo</a>
#if(strpos($video->url, "vevo.com")!==false)
<p><a target="_blank" href="{{ $video->url }}">Vevo</a>
#else <p><a target="_blank" href="{{ $video->url }}">Unknown</a>
#endif
#endforeach
Related
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
Hi guys i have trouble in making different icon for url using laravel breadcrump, , here the picture
I want to make icon HRMS and Dashboard is different
Here my blade file
<link rel="stylesheet" type="text/css" href="{{ asset("/css/hrms2.css") }}">
#if (count($breadcrumbs))
<ol class="breadcrumb">
#foreach ($breadcrumbs as $breadcrumb)
#if ($breadcrumb->url && !$loop->last)
<li class="breadcrumb-item" style="">
<a class="bread-color" href="{{ $breadcrumb->url }}">
<i class="fa fa-home"></i> {{ $breadcrumb->title }}</a>
</li>
#else
<li class="breadcrumb-item active">{{ $breadcrumb->title }}</li>
#endif
#endforeach
</ol>
#endif
You need to pass icon name also in $breadcrumb object and use $breadcrumb->icon instead of fa-home
<ol class="breadcrumb">
#foreach ($breadcrumbs as $breadcrumb)
#if ($breadcrumb->url && !$loop->last)
<li class="breadcrumb-item" style=""><a class="bread-color" href="{{ $breadcrumb->url }}"> <i class="fa {{ $breadcrumb->icon }}"></i> {{ $breadcrumb->title }}</a></li>
#else
<li class="breadcrumb-item active">{{ $breadcrumb->title }}</li>
#endif
#endforeach
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.
help or assist as it does not turn out to make sorting on categories, I can not understand as to solve this problem.
I recently study laravel.
Controller: class ArticlesController
public function showAll ($category_id)
{
$categories = Category::where('name', $category_id)->get();
return view('categories')->with(compact('categories', 'articles'));
}
This view from which I want to go into categories. site.blade.php
#foreach($categories as $category)
<li><a class="nav-link text-white" href={{route('articlesShow', ['id'=>$category->id]) }}">{{ $category->name }}</a></li>
#endforeach
Route:
Route::get('/categories/{category_id}', 'ArticlesController#showAll')->name('articlesShow');
Model: Category
public function articles()
{
return $this->hasMany(Article::class, 'category_id');
}
Representation in which does not get to get: categories.blade.php
#foreach($categories->articles as $article)
<div class="col-6 col-lg-4"> <!--Post -->
<img src="{{ asset('upload/image/1.jpg') }}" width="255" alt="..." class="rounded img_size">
<h4> {{ $article->title }}</h4>
<h6>Category: {{ $article->category->name }}</h6>
<h6>Author: {{ $article->author }}</h6>
<p>{{ $article->text }} </p>
<p><a class="btn btn-secondary" href="{{ route('articleShow', ['id' =>$article->id]) }}"> More »</a></p>
</div><!--EndPost-->
#endforeach
$categories is an array that contains categories, and the articles property belongs to a category, therefore you have to loop the categories before you can access the articles.
try this:
#foreach($categories as $category)
#foreach($category->articles as $article)
<div class="col-6 col-lg-4"> <!--Post -->
<img src="{{ asset('upload/image/1.jpg') }}" width="255" alt="..." class="rounded img_size">
<h4> {{ $article->title }}</h4>
<h6>Category: {{ $article->category->name }}</h6>
<h6>Author: {{ $article->author }}</h6>
<p>{{ $article->text }} </p>
<p><a class="btn btn-secondary" href="{{ route('articleShow', ['id' =>$article->id]) }}"> More »</a></p>
</div><!--EndPost-->
#endforeach
#endforeach
First of all: use eager loading.
Assuming, your ArticlesController#showAll method should display all articles for a given category id, your query should look like this
public function showAll ($category_id)
{
$categoryArticles = Category::with('articles')->where('id', $category_id)->get();
return view('categories')->with('categoryArticles', $categoryArticles);
}
Then to display all articles for the given category (assuming an article has only one category), this could be one way:
#foreach($categoryArticles->articles as $article)
<div class="col-6 col-lg-4"> <!--Post -->
<img src="{{ asset('upload/image/1.jpg') }}" width="255" alt="..." class="rounded img_size">
<h4> {{ $article->title }}</h4>
<h6>Category: {{ $categoryArticles->name }}</h6>
<h6>Author: {{ $article->author }}</h6>
<p>{{ $article->text }} </p>
<p><a class="btn btn-secondary" href="{{ route('articleShow', ['id' =>$article->id]) }}"> More »</a></p>
</div><!--EndPost-->
#endforeach
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>