Getting error exception "array to string conversion"

Posted 4 months ago by Gabotronix

I'm getting the following error thrown when I try to save an email into a database, what I'm trying to do is the classic subscription system.

This is my full error:

exception: "ErrorException"
file: "C:\xampp\htdocs\Restaurante1\vendor\laravel\framework\src\Illuminate\Database\Grammar.php"
line: 39
message: "Array to string conversion"
8: Object { file: "C:\xampp\htdocs\Restaurante1\app\Http\Controllers\SubscriptionController.php", line: 44, function: "save", … }
9: Object { function: "store", class: "App\Http\Controllers\SubscriptionController", type: "->" }

This is my JQuery code:
        var form = $(this).closest('form');
        console.log('button start subscription clicked');
        var emailval=$("input[name='email']").val();
            headers: {'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')}
            async: true,
            cache: false,
            url: '/subscriptions',
            type: 'POST',
            'email': emailval
            dataType: 'JSON',
            success: function (data) { 
                $('.form_valid_container').html('<span class="form_valid_text">✓ '+ data.success +'</span>');
            error: function (data){
                var errors = data.responseJSON;
                $.each(errors , function(){
                    $('.form_error_container').html('<span class="form_error_text">✘ '+ errors.message +'</span>')



And my controller where I save the email to a database:

public function store(StoreSubbedMail $request)
        $subscription = new Subscription();
        $subscription->email = $request->email;
        return response()->json([
            'success' => 'Te subscribiste correctamente'

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.