Laravel 6 Tutorial for Beginners #21 - Arrays & JSON

preview_player
Показать описание
Hey all, in this Laravel tutorial we'll see how to essentially save array data to the database (as a JSON string).

🐱‍👤🐱‍👤 JOIN THE GANG -
----------------------------------------
🐱‍💻 🐱‍💻 My Udemy Courses:

🐱‍💻 🐱‍💻 Course Links:

🐱‍💻 🐱‍💻 Other Related Free Courses:

🐱‍💻 🐱‍💻 The Net Ninja Community Boards:
Рекомендации по теме
Комментарии
Автор

Thanks Net Ninja for this tutorial :)
I'm writing some errors that I faced and how I solved it.

First when you don't select any toppings and you submit you will have an error for submitting not null values.
Second in the foreach the way that it was written in the video was throwing an error [htmlspecialchars() expects parameter 1]
To fix all this I added:
1- In the migration file
2- In the show.blade.php the following code:
@if($pizza->toppings == null)
<p>No toppings</p>
@else
<ul>
@foreach( $pizza->toppings as $key=>$topping )
<li>{{$topping}}</li>
@endforeach
</ul>
@endif
3- another this that could throw error is not inserting values to the created_at and updated_at when submitting. So, I passed an argument to the timestamp as following
$table->timestamps('added_on', 2);


 All those errors might occur because I am working with laravel and sqlite only without XAMPP :)

at
Автор

This was amazing, thank you so much my friend.
I really liked the way you handle arrays in this tutorial and loved "$casts" technique, It's awesome.

gkia
Автор

really, really, thank you so much, i've been looking for a solution for over 2 weeks

ingivanespinoza
Автор

Just taking a moment to say thank you very much again Shaun for these awesome tutorials. you're a legend.

SaintPepsiSanCoca
Автор

Congratulations bro. Your channel is growing faster than before.

mudassirsayed
Автор

Awesome tutorial. This solved my longing problem. Thank you sir

kuratandutv
Автор

This helped me so much. Perfect example!

kapkap
Автор

If you don't have MySQL 5.7 or equivalent which has the JSON type supported you can use $table->string('toppings'); in the migration and this tutorial still works fine.

mikesmyth
Автор

Thank you very much for this tutorial. Its really helped me and i love it

serkantackran
Автор

your tutorial is amazing~ thank u so much! I still have a question. if I'd like to edit the file. which approach I could use to deal with the JSON format.

zihangyu
Автор

@The Net Ninja doesn't this practice (putting multiple values in a single row) break the normalization rules in database? Or is it considered a single value since it's a list?

johnandrew
Автор

Thanks for the best ninja ever <3 just asking about JSON file and the difference between it and the array.

booksaspsds
Автор

hello ty for the tutorials, i have one question... from which version of mariadb / mysql can I use the JSON data type?

rogeerabarca
Автор

01:52 -> If anyone's facing an error: Base table or view already exists: 1050 Table x already exists

Add the following before "Schema::create('pizzas', " :


Ahmed-gvlg
Автор

Can we actually use php's serialize method instead casts thing?

srdjagunjic
Автор

what can i do to display an array from a database that has key and value?

atekeltafework
Автор

In laravel 8 i was getting "Array to string conversion " exception error. Can you help me fix that?

vancouver
Автор

Great Tutorial. If you do not select any toppings, it gives an error. How do you set the default for json data type

sundayadetona
Автор

I refreshed migrations after adding json field. After that I checked database field type in phpMyAdmin. But theres is no json field. That is longtext.

chandikalakshan
Автор

You didn't use protected fillable in pizza model but still it's inserting data. How's that

tarunkmr