skip to Main Content

How to load a relationship in Laravel without foreign key?

I have this model: AppControllersImageController.php ..... $image = new Image; $image->id = "pre_" . (string) Str::ulid()->toBase58(); $image->filename = $filename $image->post_id= $post_id; $image->save(); return $image->load("post:id,status,subject,body"); it is working fine, it returns the following: { "id": "pre_1BzVrTK8dviqA9FGxSoSnU", "type": "document", "filename": "v1BzVc3jJPp64e7bQo1drmL.jpeg", "post_id":…

VIEW QUESTION

How can I display book details in Laravel using Eloquent join and where clauses?

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…

VIEW QUESTION
Back To Top
Search