spoon

Duplicate query

Posted 3 years ago by spoon

Hello.

No matter what I do, all the books are being fetched from the database, even though I use the $id. Laravel DebugBar warned me and I started investigating this, but couldn't find the reason.

Main.php (My router)

Route::group(['namespace' => 'Book', 'prefix' => '',], function()
{
    Route::get('book/{id}/{slug}', 'BookController@bookIndex');
});

Here's my BookController.php

<?php
namespace App\Http\Controllers\Frontend\Book;
use App\Models\ThingComment;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Models\Thing;
use App\Models\User;
use App\Models\UserImage;
use App\Models\Person;
use App\Models\BookxAuthor;


class BookController extends Controller
{

    public function bookIndex($id, $slug)
    {

        $request_slug = Thing::find($id)->slug;

        if ($slug !== $request_slug)
        {
            return redirect("book/$id/$request_slug");

        }  else
        {
            $books = Thing::find($id)->get();
            $authors = Thing::FindorFail($id)->person;
            $cover = Thing::FindorFail($id)->thingImage;
            $comments = ThingComment::where('thing_id', $id)->orderBy('comment_date', 'desc')->get();

            return view('frontend.book.index')
              ->with('books', $books)
              ->with('authors', $authors)
              ->with('cover', $cover)
              ->with('comments',$comments);
        }
    }
}

index.blade.php

{{-- book info --}}
@foreach($books as $book)
    <p>{{$book->turkish_name}}</p>
    <p>{{$book->original_name}}</p>
    <p>{{$book->publication_date}}</p>
    <p>{{$book->turkish_synopsis}}</p>
    <p>{{$book->book_language}}</p>
    <p>{{$book->original_language}}</p>
    <p>{{$book->number_of_pages}}</p>
    <p>{{$book->isbn}}</p>
    <p>{{$book->release_date}}</p>
@endforeach


{{-- author--}}

@foreach($authors as $author)
    <p>{{$author->person_name}}</p>
@endforeach

{{-- cover --}}
@foreach($cover as $bookcover)
    <p>{{$bookcover->value}}</p>
@endforeach


{{-- comments --}}
@foreach($comments as $comment)
    {{$comment->comment}}
    {{$comment->thingCommentOwner->name}}
    {{$comment->thingCommentOwner->defaultAvatar->value}}
    <p></p>
@endforeach

Please sign in or create an account to participate in this conversation.