In Laravel Controller file, I have code like this
$WhiteListEmail = new WhiteListEmail();
dd($WhiteListEmail);
and in chrome browser, it returns
^ SunnyVisionWpCustomSearchModelsWhiteListEmail {#1021
#connection: "phish"
#table: "white_list_email"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: false
+wasRecentlyCreated: false
#attributes: []
#original: []
#changes: []
#casts: []
#classCastCache: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: array:1 [
0 => "email"
]
Does
#connection: "phish"
describe it really connected to a database or it just represent
I set this attribute in the model.php file?
I tried to google, but not much news on that.
2
Answers
Fill your table with a single record or more than try this code :
explaination :
the first row is to get all data that exist in your table, and the second row is to show the data(s) using dd. if you can find the data in the output, then it’s already connected and ready to use.
note :
laravel model can be connected automatically if you named your model using the singular form of the table name. eg :
in Laravel naming conventions, model name best written using Camel Case while table name best written using lower case with undescore "_" as word separator.
Here’s a reference if you want to learn more about Laravel Naming Conventions
Sorry for my bad english.
use
->exists
property to check if a model has been persisted on the database