skip to Main Content

Undefined property: IlluminateDatabaseQueryBuilder::$title

public function show(string $id) { 
    $books = DB::table("book_tbls")
        ->where("author_tbls.id", "=", $id)
        ->where("author_tbls.id", "=", "book_tbls . author_id")
        ->where("categories.id", "=", $id)
        ->where("categories.id", "=", "book_tbls . category_id");   
    
    // $books = book_tbl::find($id);
    return view('books.show', compact('books'));
}

I am learning laravel for 3 months, Now I am writing library system. In show function, I will show the details of the books eg. author name, book title and category but when I join those tables the properties are not shown. Please help.

2

Answers


  1. joins are missing. here i am adding the joins

    public function show(string $id) {
    $books = DB::table("book_tbls")

    1. List item

       ->join("author_tbls", "book_tbl.author_id", "author_tbl.id")
       ->join("categories_tbl", "book_tbl.category_id", "categories.id")
      ->where("author_tbls.id", "=", $id)
      ->where("categories.id", "=", $id)
      

      // $books = book_tbl::find($id);
      return view(‘books.show’, compact(‘books’));
      }

    Here I assume in book_tbl we have column name author_id. author_id column referencing to author id exists in author_tbl. same for the categories

    Login or Signup to reply.
  2. Try this

    public function show(string $id) {
    $books = DB::table("book_tbls")
        ->join("author_tbls", "author_tbls.id", "=", "book_tbls.author_id")
        ->join("categories", "categories.id", "=", "book_tbls.category_id")
        ->where("author_tbls.id", "=", $id)
        ->where("categories.id", "=", $id)
        ->select("book_tbls.*")
        ->get();
    
    return view('books.show', compact('books'));
    

    }

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search