Answer the question
In order to leave comments, you need to log in
How to properly store JSON in Laravel?
I am saving data. Some data is stored as varchar and stored without problems, and some must be converted to json - that's the problem.
Saved like this :
{"news": "{\"add\":null,\"edit\":null,\"delete\":null,\"editMy\":null,\"deleteMy\":null,\"reason \":\"on\",\"premoderator\":\"on\"}", "comments": "{\"add\":\"on\",\"edit\":null,\ "delete\":null,\"editMy\":null,\"deleteMy\":null,\"reason\":\"on\",\"premoderator\":null}"}
{"news": {"add": false, "edit": false, "show": true, "delete": false, "editMy": false, "reason": true, "deleteMy": false, "premoderator ": true}, "comments": {"add": true, "edit": false, "show": true, "delete": false, "editMy": false, "reason": true, "deleteMy": false, "premoderator": false}}
'site_role' => json_encode([
'news' => json_encode([
'add' => $request->newsAdd,
'edit' => $request->newsEdit,
'delete' => $request->newsDelete,
'editMy' => $request->newsEditMy,
'deleteMy' => $request->newsDeleteMy,
'reason' => $request->newsReason,
'premoderator' => $request->newsPremoderator
]),
'comments' => json_encode([
'add' => $request->commentsAdd,
'edit' => $request->commentsEdit,
'delete' => $request->commentsDelete,
'editMy' => $request->commentsEditMy,
'deleteMy' => $request->commentsDeleteMy,
'reason' => $request->commentsReason,
'premoderator' => $request->commentsPremoderator
])
])
protected $casts = [
'site_role' => 'array',
'moder_role' => 'array',
'admin_role' => 'array',
];
$role->site_role['news']['editMy']
Answer the question
In order to leave comments, you need to log in
Regional zone implies a site in the language of the region, focused on visitors from the region
. Zone .com - in the language of the region and / or English, focused on visitors from anywhere
. Zone .uk - the regional zone of Britain :)
If there is an opportunity and loot, it is better to take two.
I’ll tell you my story, now I’m creating an international site on a similar topic, Knowing this, I didn’t dare to purchase a domain in the com, ru, org, net zone,
Since it will be more of a news blog, as well as a travel blog and the like, I chose the Press zone, in my opinion, is ideal, since a diverse information site, when it was purchased, cost 200 rubles, but its current cost is $ 104. You need to understand first of all whether you are ready to further develop your site, or you are making this site for the purpose of selling ? if the second option, domain plays a big role since it is a kind of investment. The better the domain name is chosen, the more valuable the site is.
Make one domain. If you want for different countries, then choose international. If for a specific country - regional.
I recommend an article on this topic .
So why did you wrap internal arrays in json_encode?
You get json with two lines inside.
Enough site_role => json_encode(...)
Why do you need View if you give Json?
Directly in the controller do return $role->site_role['news']['editMy']; and don't need any view
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question