Tags down


How can I update json data in MySQL with Laravel framework?

By : Android_newbie
Date : July 29 2020, 07:00 PM
I think the issue was by ths following , I want to create a ticketing system with Laravel. I store the chat data's in json data type. when user want to send her/his ticket i get her/his data and store its with these code: , You have 2 options:
code :
$tiket = DB::table('synon_subsystem_ticketing')->find($id);

$messages = json_decode($ticket->messages) ?? []; //json_decode is not necessary if you're using attribute casting on your model
$messages[] = array(
    'message_body' => post('sendText'),
    'type' => 'q',
    'created_at' => date('Y/m/d H:i:s'),
$messages = json_encode($messages); //json_encode is not necessary if you're using attribute casting on your model

    ->where('id', $id)
    ->update(['messages' => $messages]);

Share : facebook icon twitter icon

read JSON data sent using post in jquery with laravel framework

By : vicheka keo
Date : March 29 2020, 07:55 AM
help you fix your problem Laravel 5.3 expects input to be sent in array format https://laravel.com/docs/5.3/requests#retrieving-input
Request sent through jQuery
code :
        url: 'http://weburl.com/api/user/create',
        dataType: 'json',
        type: 'POST',
        data: {'user': user},
        success: function(data) {
            this.setState({data: data});
        error: function(xhr, status, err) {
            console.error(null, status, err.toString());
public function create(Request $request)

    $user = new User();
    $user->name = $request->input('user.name');
    $user->email = $request->input('user.email');
    $user->password = $request->input('user.password');


    return response($user, 201);

Update json data in laravel 5.6

By : user1689212
Date : March 29 2020, 07:55 AM
like below fixes the issue @Kristly D'sena, replace input name attribute "addr" to "addr[]" with a name of the array, Then and only then you will get multi-address in the array format in post method and then convert those addresses fields into the json using json_encode
Replace below script in your edit.blade.php file.
code :
 @foreach($book->address as $value)
                <div class="col-xs-12 col-sm-12 col-md-12">
                <div class="form-group">
                    <strong>Address<?php echo  $num ?> :</strong>
                    <input type="text" name="addr[]" value="{{ $value['address'] }}" class="form-control" placeholder="Address">
                <div class="col-xs-12 col-sm-12 col-md-12">
                <div class="form-group">
                    <strong>Country <?php echo  $num ?>:</strong>
                    <input type="text" name="country[]" value="{{ $value['country']}}" class="form-control" placeholder="Country">
                <?php  $num++ ?>
public function update(Request $request, Book $book)

    $inputs = $request->all();
    $addr = ($request->addr);
    $country = ($request->country);
    $final_address = array();
    foreach ($addr as $key => $value) {
        $final_address[] = array('address' => $value, 'country'=>$country[$key] );
    $inputs['address'] = json_encode($final_address);        

    return redirect()->route('books.index')->with('success','Book updated successfully');

Laravel 5.8 update mysql json column cast as array changes data stored format

By : Desi Yanto Budisusil
Date : March 29 2020, 07:55 AM
To fix this issue The reason why it's saving differently is because array_diff returns an associative array whereas your initial data is an indexed array. Take the following for example:
code :
$ids = [1, 2, 3, 4, 5];
$ids2 = [1, 2, 3];
    3 => 4,
    4 => 5
$row_ids = array_values(array_diff($row_ids, $row_id_array));

How to make update data of mysql in laravel

By : user3079851
Date : March 29 2020, 07:55 AM
This might help you I'm trying to make an update with values from a form and pass it into an update controller using a route, there's no error given but why there's nothing happen after I updated the data? , In you scenario this another of doing this:
code :
  public function update(Request $request, $id)

    $this->validate($request, [
        'image' => 'required|image|mimes:jpg,png,jpeg'

    $kode_manga = $request->input('kdmanga');

    //getting the target row to updae
    $addmanga = DB::table('add_manga')->select('*')

    $id = $addmanga->id; // getting the id of the target

    $add_manga = App\YOUR_MODEL_NAME::find($id);

    $add_manga->judul_manga = $request->input('jdmanga');
    $add_manga->alt_title = $request->input('almanga');
    $add_manga->author = $request->input('aumanga');
    $add_manga->status = $request->status;
    $add_manga->uploaded = $request->input('lumanga');
    $add_manga->genre = $request->input('grmanga');
    $add_manga->latest = $request->input('lcmanga');
    $add_manga->summary = $request->input('sinopsis');
    $add_manga->file = $request->file('image');


    return redirect('/admin_page/manga_list');

How to update a JSON data that came from a mysql database using laravel or just a native php?

By : NewProgrammer
Date : March 29 2020, 07:55 AM
should help you out I have a database table with a type of longtext since I changed the structure to JSON because I will put a JSON data there and inserting there is is just fine. My problem is I want to update a part of that JSON data after retrieving it using laravel/php. , try this one, that's work for me!
code :
    ->where('id', $prod_id)
         "Amethyst-Cream->qty" => "2998"
Related Posts Related Posts :
  • How come my script can't check the database for similar usernames?
  • Sorting a belongsToMany relationship by an array of ids
  • Does PHP have a built-in means of determining the oldest PHP version compatible with a given PHP script? Or will it ever
  • user is being sporadically logged out (only happens in Chrome)
  • Why does php allow invalid return type declerations it knows it can't allow?
  • How to use Eloquent to retrieve certain File Types from a File Table?
  • rewrite prefix url in nginx location
  • Gitlab Repository to Heroku
  • Woocommerce - change default value tax class
  • Warning: A non-numeric value encountered in php time script
  • Generate multiple files with laravel command
  • Delete data in response array with php
  • PHP Multidimensional JSON Array to HTML Table
  • Remove term only if it is on its own line
  • Get instance of subtype of a model with Eloquent
  • Docker project using $_SESSION variable not created
  • How to Create matrix of dynamic arrays into one array?
  • Heroku 403 Forbidden - Laravel 5
  • How do I require authentication for POST requests but allow unathenticated use for GET requests on my token-secured API?
  • Symfony\Component\Debug\Exception\FatalErrorException Trait not found in Laravel project
  • PHP OOP "tail -f" functionality failing
  • How to install any php extension in AWS Amazon Linux AMI?
  • PHP : array_intersect not giving expected result
  • Contact Form without ajax just php and html page
  • How to fix the issue:Your PHP installation appears to be missing the MySQL extension
  • Two users on a session filter
  • I need to convert all the PDO in my function to MYSQLI but can't find the PDO alternatives
  • $_POST is not what I expect it to be
  • XAMPP - How can I execute PHP files from home directory?
  • Laravel - whereHas last relation is = 'manual'
  • How to get CSV integers read as integers from a string variable
  • Error: An uncaught Exception was encountered
  • Waiting until a variables value isset to display it php
  • In PHP: what is the difference between "return", "yield", "yield from" and mixing both yie
  • Cookie not registered at http (in php)
  • How to connect to a database with semicolon in the name?
  • Can't connect to database with pdo
  • Using count in in query with left join
  • How to make carousel image slide in php laravel from public folder
  • How to Implement Video Ads like YouTube and Netflix that shows before playing the actual video
  • Get username using select prepared statement
  • Save login form data using php
  • Why do I get undefined function isset() on Laravel
  • Laravel table relationship to pivot table
  • how to autorun php file per day
  • php + mysql query returning only a single row (std class) from class function
  • Error class not found when I extends a class
  • How to create a simple form on my website (cPanel based) that only activates during certain periods?
  • How to send Image and Text with JQuery AJAX
  • Get and display the selected variation SKU in WooCommerce
  • Laraval how to update column in a database with a function in a view
  • Which one will give fast result in laravel eloquent?
  • Tunnelling / Proxy SSH
  • Not finding the right syntax to use near '1' at line 1 [mysqli]
  • inserting data into database using ajax from a table
  • How to convert an array as follows?
  • How to insert value into an HTML form using PHP?
  • Laravel database relationships not working
  • How to Replace a PHP File With an Existing PHP File
  • Regex ignore the delimiter in parentheses
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org