im new at laravel backpack.
Here i want to change the title in layout with my data in database
this is the image
i want change that 'Backpack' with name in database like:
$user = DB::table('users')->where('users_id','=', '1')->get('users_name');
can i know how to change it with
the 'users_name' from database? Until know i dont know how to change it.
Thanks before
It's in the project_name/resources/views/vendor/backpack/base/layout.blad.php
<header class="main-header">
<!-- Logo -->
<a href="{{ url('') }}" class="logo"> <!-- Here's what r u looking for -->
<!-- mini logo for sidebar mini 50x50 pixels -->
<span class="logo-mini">{!! config('backpack.base.logo_mini') !!}</span>
<!-- logo for regular state and mobile devices -->
<span class="logo-lg">{!! config('backpack.base.logo_lg') !!}</span>
</a>
<!-- Header Navbar: style can be found in header.less -->
<nav class="navbar navbar-static-top" role="navigation">
<!-- Sidebar toggle button-->
<a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
<span class="sr-only">{{ trans('backpack::base.toggle_navigation') }}</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
#include('backpack::inc.menu')
</nav>
</header>
1st Way (recommended)
{!! config('backpack.base.logo_mini') !!} to
{{ DB::table('users')->where('users_id','=', '1')->get('users_name') }}
Or whatever.
2nd Way
In the project_name/config/backpack/base.php
// Menu logos
'logo_lg' => '<b>Back</b>pack',
'logo_mini' => '<b>B</b>p',
Edit '<b>Back</b>pack' for your custom large size logo and edit '<b>B</b>p' for your custom mini size logo .
UPDATE
If you want to show the authenticated user name,
{{ Auth::user()->user_name }}
Related
How can I insert a view blade inside another view in blade engine in laravel
I am working in a project that's contains :
home view ......"home.blade.php"
I want to add another page "home2.blade.php"
So finally I got 1 page which is "home.blade.php" but it contains "home2.blade.php"
this is the home2.blade.php
#extends('layouts.app')
#section('content')
<!-- All Posts -->
#if(count($posts) > 0)
<div class="panel panel-default">
<div class="panel-heading">
All Posts
</div>
<div class="panel-body">
<table class="table table-striped task-table">
<!-- Table Headings -->
<thead>
<th>Title</th>
<th>Content</th>
</thead>
<!-- Table Body -->
<tbody>
#foreach($posts as $post)
<tr>
<td class="table-text">
<div>{{$post->title}}</div>
</td>
<td class="table-text">
<div>{{$post->content}}</div>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
#endif
#endsection
and this is "home.blade.php"
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body data-spy="scroll" data-offset="0" data-target="#navigation">
<!-- Fixed navbar -->
<div id="navigation" class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse"
data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
use include() in home.blade.php
Ex: if your home2 is located in resources/views/
#include('home2')
Ok, this is what I tried and I can confirm that this works, at least for Laravel 5+ (I have L5.2). This is how I suggest you to use your blade templates.
Lets start saying that to yield a section into another section you have to define your included section before container section definition. So, with that clear, I solved this situation like this:
I got a main blade (main.blade.php) template which has something like:
<section class="content">
<!-- Your Page Content Here -->
#yield('main-content')
</section><!-- /.content -->
I got a second blade (common.blade.php) template which has that common stuff you may want to show across many pages and where main-content section is defined. This one looks like:
#section('main-content')
<div class="container">
#yield('extra-content')
</div>
#endsection
Finally I got a 3rd template (test.blade.php) which extend the main template and include the common stuff I want to show, but be careful because the order matters. This one looks like:
#extends('main')
#section('extra-content')
<div>
<span> This is a test! </span>
</div>
#endsection
#include('common')
In your controller or your route (wherever you return your view), you should return the 3rd template.
Hope this will help you
you can use the #include('filename') directive. laravel documentation
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body data-spy="scroll" data-offset="0" data-target="#navigation">
<!-- Fixed navbar -->
<div id="navigation" class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
#include('home2') <-- your home2.blade.php file will be added here
I'm a newbie in laravel and actually I have to write the sidebar in every blade of the application to make it work, but I'd like using a different sidebar depending on the section of the site where I am.
So this is what I'm trying to do:
EDIT 1
layouts/main.blade.php
<div class="wrapper">
<div class="sidebar" data-color="brown" data-active-color="danger">
<div class="logo">
<!-- Content -->
</div>
<!-- Sidebar -->
#if(request()->is("{{ url('/')}}/{operator}"))
#include('operator.sidebar')
#else
#include('stduser.sidebar')
#endif
<!-- End sidebar -->
</div>
<div class="main-panel">
<!-- Navbar -->
<nav></nav>
<!-- End navbar -->
<!-- Main content section -->
#yield('main-panel')
<!-- End main content section -->
<!-- Footer -->
<footer></footer>
<!-- End footer -->
</div>
</div>
stduser/dashboard.blade.php
#extends('layouts.main')
#section('main-panel')
<!-- Main panel contents -->
#endsection
#section('extrajs')
<!-- script contents -->
#endsection
stduser/sidebar.blade.php
<div class="sidebar-wrapper">
<div class="user btn-rotate">
<div class="photo">
<i class="fa fa-user-circle-o fa-2x" aria-hidden="true" style="color:#fff"></i>
</div>
<div class="info">
<a href="{{ url('/user') }}/profile">
<span>
{{ Auth::user()->name }}
</span>
</a>
<div class="clearfix"></div>
</div>
</div>
<ul class="nav">
<li class="active btn-rotate">
<a href="{{ url('/') }}">
<i class="nc-icon nc-bank"></i>
<p>Companies</p>
</a>
</li>
</ul>
</div>
operator/sidebar.blade.php
<div class="sidebar-wrapper">
<div class="user btn-rotate">
<div class="photo">
<i class="fa fa-user-circle-o fa-2x" aria-hidden="true" style="color:#fff"></i>
</div>
<div class="info">
<a href="{{ url('/user') }}/profile">
<span>
{{ Auth::user()->name }}
</span>
</a>
<div class="clearfix"></div>
</div>
</div>
<ul class="nav">
<li class="active btn-rotate">
<a href="{{ url('/') }}/{{ $operator->id }}/about">
<i class="fa fa-tachometer" aria-hidden="true"></i>
<p>DashBoard</p>
</a>
</li>
<li class="btn-rotate">
<a href="{{ url('/')}}/{{ $operator->id}}/suppliers">
<i class="fa fa-link" aria-hidden="true"></i>
<p>Suppliers</p>
</a>
</li>
<li class="btn-rotate">
<a href="{{ url('/')}}/{{ $operator->id}}/products">
<i class="fa fa-product-hunt" aria-hidden="true"></i>
<p>Products</p>
</a>
</li>
</ul>
</div>
This is how my views are structured:
Is there a way to make it work?
you can include the blade file like so #include('layouts/sidebar_' . $sidebarName) and if you want to avoid errors when include doesnt exist you can use #includeIf('view.name', ['some' => 'data'])
So you have just the include statement and the sidebar content only once
Based on your feedback to addi2113's answer, it seems like you're wanting to switch out the sidebar include based on which page you're on. There are several ways to do this. The simplest (yet least flexible) way to do this would be to show a certain sidebar based on the route. For instance, if you have a predictable route structure for all "operator" pages, such as example.com/operator/*, you could do the following by using an #if statement in your blade view. Like this:
#if(request()->is("/unique/url/pattern"))
#include('operator.sidebar')
#else
#include('stduser.sidebar')
#endif
Obviously, you can edit this to use any logic you want, but this is a somewhat simple way to handle this.
EDIT: Try this in your main.blade instead of using a section and yield:
<div class="wrapper">
<div class="sidebar" data-color="brown" data-active-color="danger">
<div class="logo">
<!-- Content -->
</div>
<!-- Sidebar -->
<div class="sidebar-wrapper">
<div class="user btn-rotate">
<div class="photo">
<i class="fa fa-user-circle-o fa-2x" aria-hidden="true" style="color:#fff"></i>
</div>
<div class="info">
<a href="{{ url('/') }}/profile">
<span>
{{ Auth::user()->name }}
</span>
</a>
<div class="clearfix"></div>
</div>
</div>
#if(request()->is('/unique/url/pattern'))
#include('operator.sidebar')
#else
#include('stduser.sidebar')
#endif
</div>
</div>
</div>
EDIT 2:
Since it appears you are using a dynamic URL for the operator pages, you have two options. The first option is to make your operator routes more unique than they currently are so that you can use an asterisk to denote all routes of a current pattern. For instance, in routes/web.php, change your routes for operator pages to this type of pattern:
Route::get('/operator/{operator}/about','OperatorController#about')->name('operator-about');
By adding the operator slug into the url, you now have a UNIQUE path that you can reference. Then, in your main blade, you would reference all of the operator routes together like this:
#if(request()->is('/operator/*'))
#include('operator.sidebar')
By making the URL unique, you have made a very simple way to reference all routes where you want to show the operator sidebar.
Another option, which is not as robust in my opinion, is to refer to the specific routes by naming. For instance, using the route I defined up above with the name of "operator-about", I could show the operator sidebar like this:
#if(Route::currentRouteName()=="operator-about")
#include('operator.sidebar')
You would then expand upon this by explicitly defining all named routes that you would want to show the operator sidebar for. As you can probably tell, this will get messy if there are a lot of routes you want to include. I don't recommend to do it this way, but you can feel free to solve the problem however you want.
Let me just give you a brief introduction to the question, I'm going to be having about 20 pages on my website once a user logs in, I need to organise these pages to use the same header, so I've come to the decision to use a layout as I'm using Laravel framework, it seemed stupid to have the same header spread across the 20 pages, if I wanted to make a change it would be hell.
In Bootstrap, I didn't add any kind of active class to any of the selected pages, it was just a navigation bar, I've recently upgraded to the Bulma framework where it requires an active class on the parent tab to show the child tabs, sort of a parent and sub categorys system going on.
I'm not sure how to handle this in the Layout, I need to add an active class and I also need to choose which sub navigation to show.
I've added my code below, I was wondering if anyone could tell me how I can approach this?
The below code is my whole page, including the header (the <section class="hero is-danger inside-header">)
<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
<head>
<title>{{ config('app.name') }} - Login</title>
<link rel="stylesheet" href="assets/public/1.0/frontend/css/bulma.css?id={{ time() }}" type="text/css">
<link rel="stylesheet" href="assets/public/1.0/frontend/css/override.css?id={{ time() }}" type="text/css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body class="inside">
<section class="hero is-danger inside-header">
<div class="hero-body">
<div class="container">
<div class="columns is-vcentered">
<div class="column is-5">
<p class="title header-title">Introducing {{ config('app.name') }}</p>
<p class="subtitle">Interacting with others...</p>
</div>
<div class="column is-3"></div>
<div class="column is-4">
<a class="button is-danger is-large is-disabled join-game-button">
<i class="fa fa-sign-in"></i> Join Game
</a>
<a class="button is-success is-large is-disabled users-online-button">
<i class="fa fa-users"></i> 10
</a>
<br><br>
<a class="button is-success is-large is-disabled platform-button">Platform: Closed Beta</a>
</div>
</div>
</div>
</div>
<div class="hero-foot">
<div class="container">
<nav class="tabs is-boxed">
<ul>
<li class="is-active">
<a href="/documentation/overview/start/">
<i class="fa fa-user"></i> {{ Auth::user()->username }}
</a>
</li>
<li>
<a href="http://bulma.io/documentation/modifiers/syntax">
<i class="fa fa-university"></i> Business
</a>
</li>
<li>
<a href="http://bulma.io/documentation/columns/basics">
<i class="fa fa-user-secret"></i> Gangs
</a>
</li>
<li>
<a href="http://bulma.io/documentation/elements/box/">
<i class="fa fa-users"></i> Community
</a>
</li>
<li>
<a href="http://bulma.io/documentation/components/breadcrumb/">
<i class="fa fa-shopping-cart"></i> Store
</a>
</li>
</ul>
</nav>
</div>
</div>
</section>
<nav class="navbar has-shadow">
<div class="container">
<div class="navbar-tabs">
<a class="navbar-item is-tab is-active" href="http://bulma.io/documentation/overview/start/">Home</a> <a class="navbar-item is-tab" href="http://bulma.io/documentation/overview/start/">Profile</a> <a class="navbar-item is-tab" href="http://bulma.io/documentation/overview/customize/">Education</a> <a class="navbar-item is-tab" href="http://bulma.io/documentation/overview/classes/">Skills</a> <a class="navbar-item is-tab" href="http://bulma.io/documentation/overview/modular/">Housing</a> <a class="navbar-item is-tab" href="http://bulma.io/documentation/overview/modular/">Security</a>
</div>
</div>
</nav>
<div class="container holorp-container-fixed">
<br>
<div class="columns is-desktop">
<div class="column is-8">
<div class="message is-danger">
<div class="message-body">
<p>not sure what can even go here...</p>
</div>
</div>
</div>
<div class="column is-4">
<div class="message is-success">
<p class="message-header">Change Log <span class="is-pulled-right"><i class="fa fa-user"></i></span></p>
<div class="message-body">
<span class="tag is-dark">26/09/17</span> <code>Updates the platform with a fresh design</code><br>
<span class="tag is-dark">26/09/17</span> <code>Upgraded from Laravel 5.4 to 5.5</code><br>
<span class="tag is-dark">26/09/17</span> <code>Added core features to the admin panel</code><br>
<span class="tag is-dark">26/09/17</span> <code>Did something, can't even remember</code><br>
<br>
<p><a class="modal-button" data-target="#modal-forgotPassword" id="forgot-pw-modal">View all recent changes</a></p>
</div>
</div>
</div>
</div>
</div>
</body>
If I understand well, you need "the same header" on every page. Laravel comes with Blade Template Engine, it has a set of methods to help us.
Using the template engine, you can create your app template in resources/views/layouts/app.blade.php
using #yield you can inform what part is dynamic:
<div class="container">
#yield('content')
</div>
To reuse the template in others views, for example using two pages:
The content of file resources/views/layouts/pages/one.blade.php
#extends('layouts.app')
#section('content')
<div class="row">
<h1>Page 1</h1>
</div>
#endsection
The content of file resources/views/layouts/pages/two.blade.php
#extends('layouts.app')
#section('content')
<div class="row">
<h1>Page 2</h1>
</div>
#endsection
Using #yield, #extends and #section you can reuse any HTML template in your Laravel Application.
We can create any #yield that we need:
<div class="container">
#yield('content')
</div>
#yield('scripts')
And reuse in our pages:
#extends('layouts.app')
#section('content')
<div class="row">
<h1>More than one #yield</h1>
</div>
#endsection
#section('scripts')
<script type="text/javascript" />
console.log('using Blade Template Engine');
</script>
#endsection
There is the #include method, that includes the content of another file if you need.
#extends('layouts.app')
#section('content')
<div class="row">
<h1>Page 2</h1>
#include('forms.form2')
</div>
#endsection
UPDATE:
Knowing these things above, we can do:
#extends('layouts.app')
#section('content')
<div class="row">
<h1>You are in Item B</h1>
<ul>
<li id="liA">Item A</li>
<li id="liB">Item B</li>
<li id="liC">Item C</li>
</ul>
</div>
#endsection
#section('scripts')
<script type="text/javascript" />
var d = document.getElementById("liB");
d.className += " is-active";
</script>
#endsection
This will add the CSS class in the element with id "liB", we need to use something to identify the element, I'm using "id" property but you can use anyone, just need to check what JS method to use to get it in "d" variable. You can check this for more information Element.className
I don't use Bulma, but I believe that will do what you want.
I own a YouTube Network. For those of you who don't know what that is it's a alternative to YouTube's Ad Sense service effectively. Anyway, we have a control panel that we didn't make that tells us the total combined subscribers of all of the channels on the network. I thought that would look quite nice on our website as it may encourage people to choose my network over others. This is what the control panel looks like - https://i.imgur.com/ZfuH4BJ.png I asked a question on there comuntiy and there answer was along the lines of "It's pointless us making our API as everything we do is from YouTube's Data API. So I googled YouTube's Data API and yeah I managed to get it to work but only with 1 channel. The only way I can think of making a count on my website like the one on the control panel is by manually adding the channels into like a sum of adding the queried channel subscribers together. Also when new channels join the network it could be up to 100's per day so I wondered if there is a way to query the control panel to see when new people join the network and then send it back to my web server and add it into the code automaticly?? Below id the code of my page on my website that I display the data `
<!-- Gather YouTube Subscriber Count (PHP) -->
<?
// Calling api.
$subscribers = file_get_contents('https://www.googleapis.com/youtube/v3/channels? part=statistics&id=channel_key&key=api_key);
// Decoding json response
$response = json_decode($subscribers, true );
?>
<!-- Navigation -->
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data- toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand page-scroll" href="#page-top">RiteSide Network</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="hidden">
</li>
<li>
<a class="page-scroll" href="../index.html"><i class="fa fa-arrow-left"></i> Return</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<header>
<div class="container">
<div class="intro-text">
<div class="jumbotron" align="center" style="color:black;">
<h1>Partners</h1>
<br />
<p>Please Come back soon. This page is almost finished!</p><br /><br />
<h1>Subscribers: <? // echoing subscribers count.
echo $count = intval($response['items'][0]['statistics']['subscriberCount']);?></h1>
</div>
</div>
</div>
</header>
<p> </p>
</body>`
Any Help is greatly appreciated! If you need any more details explaining, just say.
Thanks! Charlie :)
I am currently rendering the carousel slides for Twitter Bootstrap's carousel using for-loops. For each slide, the content is dynamically inserted as well with a nested for-loop. What I want is to limit the number of items appearing in each slide (i.e. 2 items). If there are more, I would want to move them into the next slide.
So basically, for each 2 items in the inner for-loop, create a new carousel slide, but making sure it is part of the parent carousel (not a new carousel altogether).
Attached an image to hopefully illustrate my point better.
Code that I have so far (using PHP framework Laravel):
<div id="carousel-example-generic" class="carousel slide" data-interval="false">
<div class="carousel-inner" role="listbox">
#foreach ($carousel_slide) <!--rendering the carousel slide-->
<div class="item">
<div class="row">
#foreach ($inner_content) <!--rendering the items in each slide-->
<div class="col-md-6 col-xs-12">
<div class="inner-carousel-item">
{{{ $inner_content->image }}}
<span>{{{ $inner_content->caption }}}</span>
</div>
</div>
#endforeach
</div>
</div>
#endforeach
</div>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
In this scenario is recommended to use regular for loop and keep incrementing the index.
In inner cycle add 2 items and increment the counter each time. Here is the meta code for this
for (;count($arr)>0;)
build next carousel page
for (;count($arr)>0;$item=array_pop($arr))
build item on carousel page
endfor
endfor