I want to save style ratings that ranges from 1 - 4.9 on my mysql database please what datatype should i use? and i keep getting this error when i save it as a decimal(11,0) ErrorException in helpers.php line 747:Method App\Wasamar\Rating::__toString() must return a string valueMY CODE$allInputs = Input::all(); $catalogueStyleId = Input::get('catalogueStyleId'); $userId = Crypt::decrypt( Input::get('user') ); $rating = Input::get('rating'); $countUserStyleRating = count( Rating::where('catalogue_style_id',$catalogueStyleId)->where('user_id','=', $userId)->first() ); if ( $countUserStyleRating == 0 ) { # add new rating data $rating = new Rating; $rating->user_id = $userId; $rating->catalogue_style_id = $catalogueStyleId; $rating->catalogue_style_rating = $rating; $rating->save(); echo "Your rating has been noted thank you"; } 解决方案 The problem is that your decimal definition specifies no decimal points. DECIMAL(11,0) means you want to store 11 digits left of the decimal point and none after.You need to define your decimal as DECIMAL(2,1) if you want to store 0.1 to 4.9. The 2 means you want to store two total digits, and the 1 means you want 1 of those digits right of the decimal point.From the documentation:MySQL Documentation 这篇关于这是什么数据类型要保存在mysql 1-4.9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-14 05:06