Reputation: 71
I am beginner to php and Laravel and I am trying to build this simple CRUD application using mongodb as the database I am using the https://www.mongodb.com/compatibility/mongodb-laravel-intergration as the tutorial to learn how to do this I am currently getting stuck at the displaying the data in laravel I made a data base into the application using the:
'mongodb' => [ 'driver' => 'mongodb', 'dsn' => env('DB_URI','mongodb+srv://username:[email protected]/myappdb?retryWrites=true&w=majority'),'database' => 'myappdb',],
the name of the database made is myappdb and the collections name is posts Database view.
All of this seems fine but when I run the server and go into the post/first-blog-post route I get a ErrorException Trying to get property 'Title' of non-object file directory
and also it marks the line 7 in post.blade.
Model post
post
Post Controller
Controller
web route
route
Why is this happening? Also are there any better resources to make a CRUD application(any simple application) in laravel with mongodb. Because I am trying to learn but finding it difficult to follow with no guide or experience. All opinions and ideas are welcome.
Upvotes: 1
Views: 250
Reputation: 358
Try debugging little by little. I like to use the dd
function and inspect what is in the variable. It could be that you are accessing a property in the collection which does not exist. So before you let your view show the output, just use the dd()
function first. Something like dd(the_variable_I_want_to_check)
.
By the way, are you already conversant with MongoDB? If not, I would advise you take a brief look at a short introduction to MongoDB: Check it out from here: https://www.youtube.com/watch?v=2QQGWYe7IDU
If you are okay with MongoDB, try taking a look at this Playlist on Youtube that I found by "Juniors Code Raw"
https://www.youtube.com/watch?v=J0Kc3qSrNlE&list=PLdTx40waQWgHIh3Kegr14vvSF-QsRd40J
It is actually just about 7 videos only. Let me know how it goes.
Upvotes: 1