I want to show different contents depends on the category, but I got an error "Creating default object from empty value".
Now, I want to show ticket and coupon information when category_id = 1, and opening hours and regular holidays information when category_id is not 1.
How can I fix this issue? I hope someone helps me out. Thank you.
show.blade.php
@if($post->category_id= '1')
<div class="detail-content">
<ul class="detail-content-list">
<li>● Ticket</li>
<li>Man : </li>
<li>Woman : </li>
<li>● Coupon</li>
<li> : <a href=""></a></li>
</ul>
</div>
@else
<div class="detail-content">
<ul class="detail-content-list">
<li>● Opening Hours</li>
<li> lorem</li>
<li>● Regular Hokidays</li>
<li>lorem</li>
</ul>
</div>
@endif
resultsController.php
public function show(Post $post)
{
$slug = $post->slug;
$recommended_posts = Post::inRandomOrder()
->whereDate('date','>',date('Y-m-d'))
->where('category_id','=',$post->category_id)
->where('id','!=',$post->id)
->limit(7)
->get();
$posts['particular_post'] = $post;
$posts['recommended_posts'] = $recommended_posts;
return view('posts.show',compact('posts'));
}
table
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('image');
$table->unsignedBigInteger('category_id');
$table->string('meta');
$table->string('alt');
$table->string('title');
$table->string('slug');
$table->string('place');
$table->string('map');
$table->date('date');
$table->string('organizer');
$table->string('organizer_link');
$table->timestamp('published_at')->nullable();
$table->text('description');
$table->timestamps();
});
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire