On every click link changes in blade view - php

This is the blade view to create the url links
#section ('category')
<ul class="main-categories">
#foreach($category as $category)
<li class="main-nav-list">{{ $category->category }}<span class="number">{{ $category->count}}</span></li>
#endforeach
</ul>
#endsection
when i click for the first time it's working fine and the url I get is
http://localhost/shopnew/public/glassfilm/Frosted
when I click for the secon time the url I get is
http://localhost/shopnew/public/glassfilm/glassfilm/Frosted
what I am doing wrong?

Change your route as below :
#section ('category')
<li class="main-nav-list">
<a href="{{ route('glassfilm-category',['name' => $category->category]) }}"> {{ $category->category }}
<span class="number">{{ $category->count}}</span>
</a>
</li>
#endsection

asset() method is used to include CSS/JavaScript/images files.
url() method used to generate a URL to a link.
Laravel's route() method is very helpful. So you can try:
<li class="main-nav-list">{{ $category->category }}<span class="number">{{ $category->count}}</span></li>
#section ('category')
<ul class="main-categories">
#foreach($category as $category)
<li class="main-nav-list">{{ $category->category }}<span class="number">{{ $category->count}}</span></li>
#endforeach
</ul>
#endsection

Related

Missing required parameters for route issue in laravel

In my laravel based application I have following link in my admin.blade.php
<ul class="nav nav-treeview">
<li class="nav-item">
<a href="{{ route('cms.home.create') }}" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>{{ __('Home Page') }}</p>
</a>
</li>
</ul>
In my project I have another blade called, create.blade.php which is in the following path
views/cms/home/create.blade.php
I have a controller called, CmsHomeController.php for that blade
In CmsHomeController I have a method called create
public function create()
{
return view('cms.home.create');
}
Once the user clicks on the above mentioned link in the admin.blade.php, user should go to the create.blade.php blade.
And in my web.php I have registered my route as follows,
Route::resource('cms.home','CmsHomeController');
But now the issue is,
When I click on that link in admin blade, I'm getting an error saying
Facade\Ignition\Exceptions\ViewException
Missing required parameters for [Route: cms.home.create] [URI: cms/{cm}/home/create]. (View: C:\xampp\htdocs\mylaravelproject\resources\views\layouts\admin.blade.php)
In create.blade.php , I'm having just a simple form
Where am I doing wrong and what would be the correct fix?
UPDATE:
I tried running
php artisan route:list
This is what I got
I don't have such a param called, 'cm'..
As you are using dot (.) operator in your resource route it will generating nested routes.
You need to change your route name with single name like cms-home or cms_home
Then you can simple use it as:
Route::resource('cms_home','CmsHomeController');
In your blade you can call it:
<a href="{{ route('cms-home.create') }}" class="nav-link">
Please have look at this referance
Your route need a parameter (cm)
You should have in your template href="{{ route('cms.home.create', ['cm' => $id_cm]) }}"
If you need the route be cms.home, try this:
Route::resource('cms.home', 'CmsHomeController', [
'parameters' => ['cms' => 'cms']
]);
Just Pass the value in your route cms.home.create like this.
<ul class="nav nav-treeview">
<li class="nav-item">
<a href="{{ route('cms.home.create', ['cm' => $value]) }}" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>{{ __('Home Page') }}</p>
</a>
</li>
</ul>

Symfony redirect to a part of page

I have a symfony page composed of 3 parts ( and i'm using tags to display each part) by navigation menu here is the navigation menu.
<ul class="nav nav-tabs centered">
<li class="active">
{{ 'fiche_pharmacie'|trans }}
</li>
<li>
{{ 'Mon équipe'|trans }}
</li>
<li>
{{ 'Configuration_automate'|trans }}
</li>
{# <li>
{{ 'Services'|trans }}
</li> #}
</ul>
After that i call 3 twig pages to display each page content.
<div class="tab-pane" id="fiche_patient">
{{ include(':prof/Entreprise:indexdetails.html.twig') }}
</div>
<div class="tab-pane" id="my_team2">
{{ include(':prof/Entreprise:my-team.html.twig') }}
</div>
<div class="tab-pane" id="config">
{{ include(':prof/Entreprise:config.html.twig') }}
</div>
My probleme is after submit i would like to display config.html.twig page.
In my controler i tried :
return $this->redirect($this-> generateUrl('entreprise_index'.'#config'));
but it doesn't work
Any one of you have an idea ?
The correct syntax for what you are trying to do there is:
return $this->redirect($this->generateUrl('entreprise_index').'#config');
You can use redirectToRoute()
$yourRouteParams = array('param1'=>1);
return $this->redirectToRoute('entreprise_index', $yourRouteParams);
You can send the tab name as a parameter to twig. And, in the template, set the active tab according to that parameter.

Filter is not working when I click on pagination in laravel and mongo db

I have a filter functionality with pagination. Filter is working initially. When I click on pagination next button result is not showing based on filter.
eg: I have three countries in filter box. I chosen two then click on filter button then result is showing correct on first page but When I click on pagination next button all three countries result is showing not appending filter.
Thank you any help would be appreciated
Framework: laravel 5.5
Database: MongoDB
route.php
Route::match(['get', 'post'], '/search', 'SearchController#index')->name('search');
SearchController.php
public function index(SearchRequest $request)
{
$data = $request->all();
$cabin = Cabin::select('_id', 'name', 'country', 'region', 'interior', 'sleeping_place', 'height', 'other_details', 'interior')
->where('is_delete', 0)
->where('other_cabin', "0");
if(isset($request->cabinname)){
$cabin->where('name', $request->cabinname);
}
if(isset($request->country)){
$cabin->whereIn('country', $data['country']);
}
//dd($cabin->count());
if(isset($request->region)){
$cabin->whereIn('region', $data['region']);
}
$cabinSearchResult = $cabin->simplePaginate(5);
return view('searchResult', ['cabinSearchResult' => $cabinSearchResult]);
}
search.blade.php
<form action="{{ route('search') }}" method="POST" class="navbar-form navbar-left" id="search-nav-home">
{{ csrf_field() }}
<div class="form-group navbar-form navbar-left" id="prefetch">
<input type="text" class="form-control-home typeahead" name="cabinname" id="cabinname" placeholder="Search Cabin">
</div>
<ul class="nav navbar-nav" id="filter-home">
#if($services->country())
<li class="dropdown">
<!-- Dropdown in Filter -->
Country <span class="caret"></span>
<ul class="dropdown-menu dropdown-menu-home">
#foreach($services->country() as $land)
<li class="check-it-list-home"><input type="checkbox" class="check-it-home" name="country[]" value="{{ $land->name }}"> {{ $land->name }}</li>
#endforeach
</ul>
</li>
#endif
#if($services->regions())
<li class="dropdown">
Region<span class="caret"></span>
<ul class="dropdown-menu dropdown-menu-home drop-height">
#foreach($services->regions() as $region)
<li class="check-it-list-home"><input type="checkbox" name="region[]" value="{{ $region->name }}" class="check-it-home"> {{ $region->name }}
</li>
#endforeach
</ul>
</li>
#endif
</ul>
<div class="form-group navbar-form navbar-right" id="navbar-right-filter-home">
<button type="submit" class="btn btn-default-home btn-filter-home">Filter Cabins</button>
</div>
</form>
In the result View you may need to append the query link to the generated paginate link:
First in your controller, send the result of the search to the view e.g.:
....
return view('searchResult', ['cabinSearchResult' => $cabinSearchResult, 'next_query' => $data]);
Then in your View, use appends and link() method on $searchResult where you display the paginated link instead of only link() or render(), like this:
....
{{ $searchResult->appends($next_query)->links() }}
This should generate links with the query string that contains your old search query on all the pages generated.
Read more about pagination in Laravel Docs

Cannot use Auth::user() in blade template in Laravel 5.4

I want to make my index page with both guest and auth functions.
When guests visit, they could try logging in; And after login, it will show the user's info such as username.
Below is what I did.
Routes are defined in routes/web.php:
Route::get('/', 'CommonController#index');
Auth::routes();
In blade template of index, I used Auth::user() to validate authentication but failed.
#if(Auth::user())
<div id="user-panel">
<a href="" class="user-panel-button">
New Article
</a>
<div class="btn-group user-panel-button">
<a type="button" class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ Auth::user()->name }} <span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>Logout</li>
</ul>
</div>
</div>
#else
<a href="{{ url('login') }}" class="button">
Login
</a>
#endif
Every time I logged in successfully, it will still show login button instead of user name button, after I REFRESH the index page.
I have checked session information, once I refreshed the page, the login_web_xxxxxxxxxxx session will be disappeared.
Furthermore, When I use Laravel default path for auth /home, it worked. Username could always be presented whatever how many times you refresh the page.
How should I fix this issue? Many thanks.
For Laravel 5.4 you can use:
#if(Auth::check())
// The user is authenticated...
#else
// The user is not authenticated...
#endif
For Laravel 5.5 and above:
#auth
// The user is authenticated...
#endauth
#guest
// The user is not authenticated...
#endguest
Instead of using
<ul class="dropdown-menu">
<li>Logout</li>
</ul>
For log out, it is better to be codes as below, which is provided by official resources/view/layouts/app.php
<ul class="dropdown-menu">
<li>
<a 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_field() }}
</form>
</li>
</ul>
Update routes/web.php file as
Route::group(['middleware' => 'web'], function () {
Route::get('/', 'CommonController#index');
Auth::routes();
}
Now to check auth in your blade template, you can use
#if(\Auth::check())
....
....
#else
....
....
#endif
also you can use the full class path of Auth in blade file like this
#if(\Illuminate\Support\Facades\Auth::check())
// code here
#endif

Automatic translation does not work in Laravel 5.2

After changing the locale name and then print {{ Config::get('languages')[App::getLocale()] }}, it's giving me the locale name i.e. Italiano or Français. But it does not translate the website text into changed locale!
I am using following article for the localization Laravel 5.2 localization also tried Laravel Localizationbut same also there.
From my understanding, it should translate the language automatically!
Need some expert help from the community.
Sample code from my view file:
#extends('layouts.app')
#section('content')
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
{{ Config::get('languages')[App::getLocale()] }}
</a>
<ul class="dropdown-menu">
#foreach (Config::get('languages') as $lang => $language)
#if ($lang != App::getLocale())
<li>
{{$language}}
</li>
#endif
#endforeach
</ul>
</li>
<h2>Welcome to my website</h2>
<p>Please find your desired content by using website search function.</p>
#endsection
Are you expecting the text elements to translate? You need to use the trans() function and put your copy text in translation files.
EG
<h2>{{trans('welcome_message')}} </h2>
Then stick the copy in your language file
You are getting languages from nowhere, so if you want it to work, copy/paste following array in your app.php
'locales' => [
'en' => 'English',
'ka' => 'Georgian',
'ru' => 'Russian',
],
And if you call Config::get('app.locales') you will get this locales.
Here is how your code must look like:
#extends('layouts.app')
#section('content')
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
{{ Config::get('app.locales')[App::getLocale()] }}
</a>
<ul class="dropdown-menu">
#foreach (Config::get('app.locales') as $lang => $language)
#if ($lang != App::getLocale())
<li>
{{$language}}
</li>
#endif
#endforeach
</ul>
</li>
<h2>Welcome to my website</h2>
<p>Please find your desired content by using website search function.</p>
#endsection

Categories