Did you try to pass locale also to your show method?
@manof360 Try this way:
public function success_details($slug)
{
$story = Story::where($slug, 'slug')->firstOrFail();
return view('user.stories_details', compact('story'));
}
no different
You have said that everything before line
return view('user.stories_details', compact('story'));
works fine. Can you show inners of this blade file?
@manof360 i can see that the error says about the header template
<li>
<a href="{{route('success',app()->getLocale())}}">@lang('header.Success Stories')</a>
</li>
try to see this part
@lang('header.Success Stories')
if it's the right way to write it or not. What are you trying to output by this?
@martal .... this is the blade of stories details:
@extends('user.layouts.app')
@section('title',' Stories | BFD ')
@section('content')
<!-- breadcrumb-start -->
<section class="breadcrumb breadcrumb_bg banner-bg-1 overlay2 ptb200">
<div class="container">
<div class="row">
<div class="col-lg-7 offset-lg-1">
<div class="breadcrumb_iner">
<div class="breadcrumb_iner_item">
<h2>Stories </h2>
<p><a href="#">Home.</a> <span></span> Contact</p>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- breadcrumb-end -->
<!-- Stories-area-start -->
<section class="content">
<div class="row">
<div class="col-md-12">
<div class="card card-outline card-info">
<div class="card-header">
<h3 class="card-title font-weight-bold">
{{$story->E_title}}
</h3>
<!-- tools box -->
<div class="card-tools">
<a href="#" class="btn btn-primary"> <i class="fas fa-forward"></i>
Back</a>
</div>
<!-- /. tools -->
</div>
<!-- /.card-header -->
<div class="card-body pad">
<div class="">
<div class="container">
<table class="table table-hover">
<thead>
<tr>
<th>Category</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td class="bg-primary"> {{$story->category->E_name}}</td>
<td class="bg-danger"> @if (
$story->publish
== 1)
publish
@else
Not Publish
@endif</td>
</tr>
</tbody>
</table>
<hr>
<img src="{{asset('/storage/'.$story->image)}}" width="350px" height="350px"
class="rounded mx-auto d-block img-thumbnail">
<hr>
<div class="container-fluid">
<p class="text-center"> {!! $story->E_body !!}</p>
<hr>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- /.col-->
</div>
<!-- ./row -->
</section>
<!-- Stories-area-end -->
@endsection
and this the app blade :
<!doctype html>
<html class="no-js" lang="{{ str_replace('_', '-', app()->getLocale()) }}" dir="{{ (\App::isLocale('fa')) |
(\App::isLocale('en')) ? 'LTR' : 'RTL' }}">
<head>
@include('user.layouts.head')
</head>
<body>
<!--[if lte IE 9]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a
href="https://browsehappy.com/">upgrade your browser</a> to improve your experience and security.</p>
<![endif]-->
<!-- header-start -->
<header>
@include('user.layouts.header')
</header>
<!-- header-end -->
@yield('content')
<!-- footer-start -->
@include('user.layouts.footer')
and this is the header.blade
<div class="header-area ">
<div class="language-area ">
@foreach (config('app.locales') as $locale=>$name)
<a href="{{ route(\Illuminate\Support\Facades\Route::currentRouteName(), $locale) }}"
@if (app()->getLocale() == $locale) class="lang-active" @endif>{{ strtoupper($name) }}</a>
@endforeach
</div>
<div class="header-top black-bg d-none d-md-block">
<div class="container">
<div class="row">
<div class="col-xl-5 col-md-5 col-lg-5">
<div class="header-contact">
<a href="#"><i class="fa fa-phone"></i> + 967 01 443 941</a>
<a href="#"><i class="fa fa-envelope"></i> [email protected]</a>
</div>
</div>
<!-- Right Side Of Nav -->
<div class="col-xl-2 col-md-2 col-lg-2 language-style">
@foreach (config('app.locales') as $locale=>$name)
<a href="{{ route(\Illuminate\Support\Facades\Route::currentRouteName(), $locale) }}"
@if (app()->getLocale() == $locale) class="lang-active" @endif>{{ strtoupper($name) }}</a>
@endforeach
</div>
<div class="col-xl-4 col-md-4 col-lg-4">
<div class="header-top-menu">
<nav>
<ul>
<li><a href="#"> @lang('header.Building Foundation for Development')</a></li>
</ul>
</nav>
</div>
</div>
</div>
</div>
</div>
<!--white BG-->
<div id="sticky-header" class="main-header-area white-bg">
<div class="container">
<div class="row align-items-center">
<div class="col-xl-2 col-lg-2">
<div class="logo-img">
<a href="">
<img src="{{ asset('user/images/BFD_LOGO_.jpg') }}" style="width:50px; height:auto;"
alt="BFD Logo">
</a>
</div>
</div>
<div class="col-xl-7 col-lg-7">
<div class="main-menu d-none d-lg-block">
<nav>
<ul id="navigation">
<li><a class="{{Request::is('/')?'active':'' }}"
href="{{route('HomPage',app()->getLocale())}}">@lang('header.Home')</a></li>
<li>
<a href="{{route('success',app()->getLocale())}}">@lang('header.Success Stories')</a>
</li>
<li>
<a class="{{Request::is('Job_announcement')?'active':'' }}"
href="#">@lang('header.Recruitment') <i
class="ti-angle-down"></i></a>
<ul class="submenu">
<li>
<a href="{{route('Job_announcement',app()->getLocale())}}">@lang('header.Job announcement')</a>
</li>
<li>
<a href="{{route('tenders',app()->getLocale())}}">@lang('header.Tenders') </a>
</li>
<li>
<a href="{{route('volunteering',app()->getLocale())}}">@lang('header.Volunteering') </a>
</li>
</ul>
</li>
<li>
<a class="{{Request::is('about')?'active':'' }}"
href="about">@lang('header.About Us') <i
class="ti-angle-down"></i></a>
<ul class="submenu">
<li>
<a href="{{route('who_we_are',app()->getLocale())}}">@lang('header.Who we are')</a>
</li>
<li>
<a href="{{route('what_we_do',app()->getLocale())}}">@lang('header.What we do')</a>
</li>
<li>
<a href="{{route('where_we_work',app()->getLocale())}}">@lang('header.Where we work')</a>
</li>
</ul>
</li>
<li>
<a class="{{Request::is('Media')?'active':'' }}"
href="#">@lang('header.Media') <i
class="ti-angle-down"></i></a>
<ul class="submenu">
<li>
<a href="{{route('galleries',app()->getLocale())}}">@lang('header.Gallery')</a>
</li>
<li>
<a href="{{route('indicators',app()->getLocale())}}">@lang('header.indicators')</a>
</li>
<li>
<a href="{{route('reports',app()->getLocale())}}">@lang('header.Reports')</a>
</li>
</ul>
</li>
<li><a class="{{Request::is('contact_us')?'active':'' }}"
href="{{route('contact_us',app()->getLocale())}}">@lang('header.Contact Us')</a>
</li>
</ul>
</nav>
</div>
</div>
<div class="col-xl-3 col-lg-3">
<div class="quote-area">
<div class="search-bar">
<a id="search_1" href="javascript:void(0)"><i class="fa fa-search"></i></a>
</div>
<div class="get-quote d-none d-lg-block">
<a class="boxed-btn" href="#">@lang('header.Donate')</a>
</div>
</div>
</div>
<div class="col-12">
<div class="mobile_menu d-block d-lg-none"></div>
</div>
</div>
<div class="search_input" id="search_input_box">
<div class="container ">
<form class="d-flex justify-content-between search-inner">
<input type="text" class="form-control" id="search_input" placeholder="Search Here">
<button type="submit" class="btn"></button>
<span class="fa fa-close" id="close_search" title="Close Search"></span>
</form>
</div>
</div>
</div>
</div>
</div>
You have such loop in your header
@foreach (config('app.locales') as $locale=>$name)
<a
href="{{ route(\Illuminate\Support\Facades\Route::currentRouteName(), $locale) }}"
@if (app()->getLocale() == $locale)
class="lang-active"
@endif
>
{{ strtoupper($name) }}
</a>
@endforeach
It has line
href="{{ route(\Illuminate\Support\Facades\Route::currentRouteName(), $locale) }}"
which is the reason of your error. It will fail in all routes that has two or more parameters because here you have only one - $locale
Yes Mr : @martal you are right 👍 🎉 🎊
when I remove the loop everything works fine . thanks a lot for extremely helping .
I change that line to :
<a href="{{ route(\Illuminate\Support\Facades\Route::currentRouteName(),[$locale,'slug'=>$slug??'no slug ']) }}"
and now everything works well
is there any suggestion to change foreache loop to any thing else ?
Your locale is always on the first place, before first slash. So the easiest way is something like that
@foreach (config('app.locales') as $locale=>$name)
@php
$uri = Route::currentRoute()->uri;
$pieces = explode('/', $uri);
$pieces[0] = $locale;
$route = implode('/', $pieces);
@endphp
<a
href="{{ $route }}"
@if (app()->getLocale() == $locale)
class="lang-active"
@endif
>
{{ strtoupper($name) }}
</a>
@endforeach
Hi @martal I get this error : Undefined offset: 0
Facade\Ignition\Exceptions\ViewException
Undefined offset: 0 (View: C:\Users\ManOf360\Desktop\BFD+Admin- zero to
hero\BFD_Org\resources\views\user\layouts\header.blade.php)
http://127.0.0.1:8000/en
What is in $uri variable?
the logger() not work her :
logger('the uri is : ',[$uri]);
I cat find the dd() for it .
Ok. Please show me the output of php artisan route:list
C:\Users\ManOf360\Desktop\BFD+Admin- zero to hero\BFD_Org>php artisan r:l
+--------+----------+---------------------------+------------------+------------------------------------------------------------------------+---------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+---------------------------+------------------+------------------------------------------------------------------------+---------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | api/user | | Closure | api,auth:api |
| | POST | login | | App\Http\Controllers\Auth\LoginController@login | web,guest |
| | GET|HEAD | login | login | App\Http\Controllers\Auth\LoginController@showLoginForm | web,guest |
| | POST | logout | logout | App\Http\Controllers\Auth\LoginController@logout | web |
| | GET|HEAD | password/confirm | password.confirm | App\Http\Controllers\Auth\ConfirmPasswordController@showConfirmForm | web,auth |
| | POST | password/confirm | | App\Http\Controllers\Auth\ConfirmPasswordController@confirm | web,auth |
| | POST | password/email | password.email | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail | web |
| | POST | password/reset | password.update | App\Http\Controllers\Auth\ResetPasswordController@reset | web |
| | GET|HEAD | password/reset | password.request | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web |
| | GET|HEAD | password/reset/{token} | password.reset | App\Http\Controllers\Auth\ResetPasswordController@showResetForm | web |
| | GET|HEAD | {locale} | HomPage | App\Http\Controllers\HomPageController@index | web,setlocale |
| | GET|HEAD | {locale}/Job_announcement | Job_announcement | App\Http\Controllers\HomPageController@Job_announcement | web,setlocale |
| | GET|HEAD | {locale}/about | about | App\Http\Controllers\HomPageController@about | web,setlocale |
| | GET|HEAD | {locale}/contact_us | contact_us | App\Http\Controllers\HomPageController@contact_us | web,setlocale |
| | POST | {locale}/contact_us | contact_us | App\Http\Controllers\HomPageController@sendEmail | web,setlocale |
| | GET|HEAD | {locale}/galleries | galleries | App\Http\Controllers\HomPageController@galleries | web,setlocale |
| | GET|HEAD | {locale}/indicators | indicators | App\Http\Controllers\HomPageController@indicators | web,setlocale |
| | GET|HEAD | {locale}/mapData | mapData | App\Http\Controllers\HomPageController@mapData | web,setlocale |
| | GET|HEAD | {locale}/mapDetails/{id} | mapDetails | App\Http\Controllers\HomPageController@mapDetails | web,setlocale |
| | GET|HEAD | {locale}/reports | reports | App\Http\Controllers\HomPageController@reports | web,setlocale |
| | GET|HEAD | {locale}/stories | stories | App\Http\Controllers\HomPageController@stories | web,setlocale |
| | GET|HEAD | {locale}/success | success | App\Http\Controllers\HomPageController@success | web,setlocale |
| | GET|HEAD | {locale}/success/{slug} | success_details | App\Http\Controllers\HomPageController@success_details | web,setlocale |
| | GET|HEAD | {locale}/tenders | tenders | App\Http\Controllers\HomPageController@tenders | web,setlocale |
| | GET|HEAD | {locale}/volunteering | volunteering | App\Http\Controllers\HomPageController@volunteering | web,setlocale |
| | GET|HEAD | {locale}/what_we_do | what_we_do | App\Http\Controllers\HomPageController@what_we_do | web,setlocale |
| | GET|HEAD | {locale}/where_we_work | where_we_work | App\Http\Controllers\HomPageController@where_we_work | web,setlocale |
| | GET|HEAD | {locale}/who_we_are | who_we_are | App\Http\Controllers\HomPageController@who_we_are | web,setlocale |
+--------+----------+---------------------------+------------------+------------------------------------------------------------------------+---------------+
@manof360 Try this
@foreach (config('app.locales') as $locale=>$name)
@php
$route = Route::currentRoute();
$locales = array_keys(config('app.locales'));
$uri = Route::currentRoute()->uri;
if ($url != '') {
$pieces = explode('/', $uri);
if (count($pieces) > 0 && in_array($pieces[0], $locales)) {
$pieces[0] = $locale;
$route = implode('/', $pieces);
}
}
@endphp
<a
href="{{ $route }}"
@if (app()->getLocale() == $locale)
class="lang-active"
@endif
>
{{ strtoupper($name) }}
</a>
@endforeach
my friend @martal 😐 I don't know how but the same error still shows up
Facade\Ignition\Exceptions\ViewException
Undefined offset: 0 (View: C:\Users\ManOf360\Desktop\BFD+Admin- zero to hero\BFD_Org\resources\views\user\layouts\header.blade.php)
http://127.0.0.1:8000/en/success
You actually have 2 foreach loops in header.blade.php. Did you update them both?
Yes my dear friend .
I need more data to find out where is the error. I far as I know my code should not throw this error. If my piece of code does throw it then it means that there is something I do not know about.
my dear friend @martal I am sorry 😅, because I lateing to tell you if my problem has been solved or not . Actual .. I tried a lot .. then I decided to use session() to set up everything ..
I put the slug in session when the user click on the read more
@php session(['slug' => $story->slug ]); @endphp
and in route I get the slug form the session too .
@foreach (config('app.locales') as $locale=>$name)
< <a href="{{ route(\Illuminate\Support\Facades\Route::currentRouteName(),
[$locale,'slug' => session()->get('slug') ]) }}"
@if (app()->getLocale() == $locale)
class="lang-active"
@endif
>
{{ strtoupper($name) }}
</a>
@endforeach
till now everything work fine . I really grateful for your helping 😊 and I will send you if there something happen .
Ok, you are welcome!
Please or to participate in this conversation.