I have 4 different titles
users
agencies
end customers
inactive
and i have only one view (one laravel.blade.php file) with this code
#section('title')
#if (Request::is('/admin/users'))
Alle Benutzer
#elseif(Request::is('/admin/agencies'))
Agenturen
#elseif(Request::is('/admin/endcustomers'))
Endkunden
#else
Inactive
#endif
#endsection
and in my layout i have
<title>#yield('title')</title>
and in my routes i have
Route::get('/admin/users', 'AdminController#showUsers');
Route::get('/admin/agencies', 'AdminController#showAgencies');
Route::get('/admin/endcustomers', 'AdminController#showEndCustomers');
Route::get('/admin/inactive', 'AdminController#showInactiveUsers');
And which ever site i call the title is always Inactive
What am i doing wrong....why the title doesn't change?
Well, you can't use the "Request" in the view.
I suggest you send the title from the controller like this:
return view('%the name of the view%', ['title'=>"%Your title%"]);
Then in the view, you can put this
<title> {{$title }} </title>
you've got to echo the title in the #section.
#section('title')
#if (Request::is('/admin/users'))
echo("Alle Benutzer");
#elseif(Request::is('/admin/agencies'))
echo("Agenturen");
#elseif(Request::is('/admin/endcustomers'))
echo("Endkunden");
#else
echo("Inactive");
#endif
#endsection
You can do like this in Blade (view):
#switch(\Route::current()->getName())
#case('/admin/users')
Alle Benutzer
#break
#case('/admin/agencies')
Agenturen
#break
#case('/admin/endcustomers')
Endkunden
#break
#default
Inactive
#endswitch
Related
I have an #if/#else condition in a Blade file to present different values of a PHP table. The data comes from a Laravel/Livewire controller, and the Blade code that creates the issue is below.
#if(!$course->user_limit)
#if(in_array($course->id, $arrs))
<x-jet-button wire:click="confirmCourseInterest( {{ $course->id}})"
class="bg-orange-500 hover:bg-orange-700">
{{__('Κάντε κλικ για απόσυρση ενδιαφέροντος')}}
</x-jet-button>
#else
<x-jet-button wire:click="confirmCourseInterest( {{ $course->id}})"
class="bg-orange-500 hover:bg-orange-700">
{{__('Κάντε κλικ για εκδήλωση ενδιαφέροντος')}}
</x-jet-button>
#endif
#else
<div class="flex" id="user_limit_reached">
{{ __('User Limit Reached') }}
</div>
#endif
The issue occurs on the outer if/else that irregularly returns both if and else statements. The user_limit is false on the field that has the problem. Why does this happen?
Change your #else to #elseif and pass another logic there.
Sometimes blade echo doesn't print and I don't know why.
With this code visits are not printed
#extends('layouts/base', ['title' => "$url->new"])
#section('content')
<h1>Link Shortened !</h1>
{{ $url->new }}
<h3>visits {{ $url->visits }}</h3>
#endsection
With this code (removing the space after visits) the number of visits is printed
#extends('layouts/base', ['title' => "$url->new"])
#section('content')
<h1>Link Shortened !</h1>
{{ $url->new }}
<h3>visits {{ $url->visits}}</h3>
#endsection
It should work when you replace "$url->new" to $url->new in the #extends lines.
(answered in the comments by #Jinal)
I have two return varibles from controller to view in Laravel.
return view ('home', compact('books','count'));
Now I want to display one section('content') #if the conditon is true
in my home.blade.php. How I can do this. Now section('content') will display #if condition is false
#if (!empty($books))
#section('content')
#endif
You can use #else, #elseif, #unless
Here is an example
#if (count($books))
section('content')
#else
#section('your other section')
#endif
Hope this helps
hellow, I have edit.blade.php file in Laravel
#extends('layouts.app')
#section('content')
#if (isset($permission))
<div>
<p>Hellow Friends</p>
</div>
#endif
<h1>Hi</h1>
#stop
but did not display Hellow friend words. only dispaly #extends('layouts.app')
#section('content')
and Hi
how can I display Hellow Friends
While rendering the view in controller just do:
$data['permission'] = true;
return view('view_name',$data);
You should sent permission variable from the controller. The condition here fails is $permission does not exist so basically Hellow Friends will not be echoed.
In your controller you can do the following:
return view('edit', ['permission' => 'whatever_you_want_here']);
and then check for the permission in the blade file.
I'm using Blade templating with Laravel and I'm trying to use a #foreach loop to display notifications. The problem is that if I have say 10 notifications, the first notification is repeated 10 times.
The code to output each notification:
#foreach ( Auth::user()->unreadNotifications as $notification )
{{ $notification->type->web_template }}
{{ $notification->id }}
#include($notification->type->web_template)
#endforeach
web_template will output a path to the template: notifications.web.user_alert
For each iteration of the loop the {{ $notification->type->web_template }} and {{ $notification->id }} will output what they're supposed to but #include($notification->type->web_template) will only output the first notification each time.
So the output will look like:
156 notification.web.new_message
You have a new message from Joe.
154 notification.web.user_alert
You have a new message from Joe.
145 notification.web.new_like
You have a new message from Joe.
I think it's some sort of cache issue maybe, but I couldn't find anyone with the same problem.
Any ideas?
UPDATE: Adding some code
Example notification view:
#extends('layouts.notification-wrapper')
#section('url', url('jobs/'.$notification->job_id.'#highlight'.$notification->bid_id))
#section('image', '/assets/img/no-photo.jpg')
#section('header', $notification->collector->firstname . ' ' . $notification->collector->secondname)
#section('description')
has placed a bid of €{{ number_format($notification->bid()->withTrashed()->first()->amount,0) }} on your job.
#stop
Notification wrapper:
<li #if(!$notification->read)
class="unread"
#endif>
<a href="#yield('url')" data-id="{{ $notification->id }}">
<div class="pull-left">
<img src="#yield('image')" class="img-circle" alt="user image">
</div>
<h4>
#yield('header')
<small><i class="fa fa-clock-o"></i> {{ $notification->created_at->diffForHumans()}}</small>
</h4>
<p> #yield('description')</p>
</a>
</li>
Answering my own question!
Found this: Laravel Blade Templates Section Repeated / cache error
Basically whatever way it works I need to overwrite my sections when looping and using #yield... I think. So I need to replace #stop with #overwrite in my views.