add a template column to your categories
In this, store the name of the view file you want to use. When you return view, insert the template name from the database rather than hard coding the string for the view name.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Is it possible to make new design for every category as I have created category with id ex home id 1 product id 2 contact us id 3 about us id 4
thank you all
add a template column to your categories
In this, store the name of the view file you want to use. When you return view, insert the template name from the database rather than hard coding the string for the view name.
thank you @snapey , ii just made 4 category in database with the help with id.. and for home my id is 1, product id is 2 about id is 3 contact us id is 4, as i created category.blade.php where it has creating same category page designed but i want to create a new design for every category...can show my all code here
this is category.blade.php
@extends('layouts.frontend')
@section('content')
<div style="background-image:url(app/images/head/about.jpg)" class="wrap-slider my-wrap-slider">
<div class="container page-container">
<div class="page-content">
<div class="page-title">
<h1 class="tshadow">{{$category->name}}</h1>
</div><!-- page-title -->
</div>
</div><!-- container -->
</div><!-- wrap-slider -->
<div class="container">
<div class="row medium-padding120">
<main class="main">
<div class="row">
<div class="case-item-wrap">
@foreach($category->posts as $post)
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
<div class="case-item">
<div class="case-item__thumb mouseover poster-3d lightbox shadow animation-disabled" data-offset="5">
<img src="{{ $post->featured }}" alt="our case">
</div>
<a href="{{ route('post.single', ['slug' => $post->slug ]) }}"><h6 class="case-item__title">{{ $post->title }}</h6></a>
</div>
</div>
@endforeach
</div>
</div>
</main>
</div>
</div>
and this is frontend Controller
@snapey this is category one http://localhost/category/1
http://localhost/category/2 http://localhost/category/3 http://localhost/category/4
these are link with id of category and I have same designed for the all, so I want to different designed for each category /...................thank you
Where is frontend controller
Copy category.blade.php to category1.blade.php, category2.blade.php, category3.blade.php. category4.blade.php
in the controller
return view('category'.$category->id);
edit each file to suit the category
Thank you once again, I made category1.blade.php, category2.blade.php, category3.blade.php, category4.blade.php, category5.blade.php, and here is example of category1.blade.php
@extends('layouts.frontend')
@section('content')
<div style="background-image:url(app/images/head/about.jpg)" class="wrap-slider my-wrap-slider">
<div class="container page-container">
<div class="page-content">
<div class="page-title">
<h1 class="tshadow">{{$category->name}}</h1>
Hi type here only for the same category
</div><!-- page-title -->
</div>
</div><!-- container -->
</div><!-- wrap-slider -->
<div class="container">
<div class="row medium-padding120">
<main class="main">
<div class="row">
<div class="case-item-wrap">
@foreach($category->posts as $post)
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
<div class="case-item">
<div class="case-item__thumb mouseover poster-3d lightbox shadow animation-disabled" data-offset="5">
<img src="{{ $post->featured }}" alt="our case">
</div>
<a href="{{ route('post.single', ['slug' => $post->slug ]) }}"><h6 class="case-item__title">{{ $post->title }}</h6></a>
</div>
</div>
@endforeach
</div>
</div>
</main>
</div>
</div>
and frontend controller is like that
and frontend controller is like that
What does this mean?
Is your problem solved? Please mark it complete.
Still I am doing the same but its nothing happend, because I have different category id and when trying to connect its showing nothing only one desinged shows
Please try and explain the problem
ok @snapey , first I have made 4 category in my admin Home, Contact, About, Porduct and these are showing on menu list in website.
However, I have made a a single template category.blade,php as a designed for every category will have same designed.
And I want to create a different layout designed for each menu individual..
I am pasting all code below...
This is header.blade.php
<div class="btn-menu">
<span></span>
</div><!-- //mobile menu button -->
</div><!-- /wrap-search -->
<div class="wrap-nav">
<nav id="mainnav" class="mainnav">
<ul class="menu">
@foreach($categories as $category)
<li class="text-black-50"><a href="/category/{{$category->id}}">{{$category->name}}</a></li>
@endforeach
</ul>
</nav>
</div><!-- /wrap-nav -->
</div><!-- /col-md-12 -->
</div><!-- /row -->
</div><!-- /container -->
this is frontend controller
as @snapey said you can add ( template) colum in categories table and in the show method in CategoriesController
$template = 'categories/'. $category->template . '.blade.php';
return view($template, compact('category'));
Or if you don't like adding an extra column to your database table you can just tweak it using categories ids , for instance
if($category->id == 1 )
$template = "something.blade.php";
elseif
and so on
Thanks @maged , I am doing this as you told still it's nothing happend
public function up() { Schema::create('categories', function (Blueprint $table) { $table->increments('id');
$table->string('name');
$table->string('template');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('categories');
}
}
and
my categoriesConroller
@ME10071990 - please show me a screen of your Categoriescontroller + names of your view files + categories records ( i want to see what u store in template field for each category)
I have send already pasted all the code please check
Post your CategoriesController - show method
thank you ...public function show($id) {
// $category= new Category;
//$template = 'categories/'. $category->template . '.blade.php';
//return view($template, compact('category'));
}
When you show a view, you don't put .blade.php in the view command.... so why have you done it here?
How do you expect to show a category template when you don't choose the category and just load an empty model -$category= new Category;
Is this code really all commented out?
@Snapey is this not commented out, I was just checking another code for it and also using if elseif condition, please help me to correct so I can do and learn in best way... thank you very much
@maged still with the blade naming error
public function show(Category $category) {
$template = 'categories.' . $category->template;
return view($template, compact('category'));
}
or better
public function show(Category $category) {
return view( 'categories.' . $category->template, compact('category'));
}
@snapey sorry i just realized that .. you are absolutely right :)
Thank you @snapey -:) I am using this in CategoriesController public function show(Category $category) {
return view( 'categories.' . $category->template, compact('category'));
}
so what I have to do next
now in data base it's showing error.."SQLSTATE[HY000]: General error: 1364 Field 'template' doesn't have a default value (SQL: insert into categories (name, updated_at, created_at) values (HOME, 2019-04-25 12:42:37, 2019-04-25 12:42:37)) ◀" however I reset NULL
@me10071990 you didn't insert any value in the template field ,this field should include the blade name like category1 ..
make sure you insert a value there using tinker or phpmyadmin for now .
I put from phpmyadmin as a null and its working now however designed is still not going through...
public function show(Category $category) {
return view( 'categories.' . $category->template, compact('category'));
} after this what code I have to make or change.. thank you
you also might want to refer for a default template if you didn't insert one .. so in your migration add this
$table->string('template')->default('category1');
i think this would be fine .
Ok thank you , what code I need to change after that
Nothing, this should work .
Ok , so I have to make every new blade.php for each category ?
I think you first need to learn php and laravel a little first. This is taking a ridiculous number of messages for a simple request.
You create the category
You create the template for the category
You put the name of the template in the category
You display the category using the template.
How hard can it be?
Please or to participate in this conversation.