Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strpos() expects parameter 1 to be string, object given laravel 5.5

Tags:

php

laravel

This is my code:

public function getLists(Request $request)
{
    $user = $request->user()->id;
    $apikey = DB::table('apikey')->where('api_key', '=', $user);

    if($apikey){
    $mc = new MailChimp($apikey);
    $mailchimp_ping = $mc->get('lists',['fields' => 
        'lists.id,lists.name']);
    return Response::json($mailchimp_ping, 200);
    }
    else
    {        
        $errorResponse = [
            'message' => 'Lists not found!',
            'error' => '401'
        ];
        return Response::json( $errorResponse);
    }
}

I am trying to get mailchimp list based on logged in user id where i am doing wrong? is my where clause expects something else? Any help would be highly appreciated!

like image 621
syed1234 Avatar asked Nov 28 '25 01:11

syed1234


2 Answers

Use the value() method to execute the query and get the key. For example, if a column with key is called apikey:

$apikey = DB::table('apikey')->where('api_key', $user)->value('apikey');
like image 109
Alexey Mezenin Avatar answered Nov 29 '25 16:11

Alexey Mezenin


In my case this error came up when changed this:

 Route::view('/report', '/main_pages/orders_parts/report')->name('guzorishi_order_1');

to

Route::get('/report/{order_id}', function ($order_id) {... })->name('guzorishi_order_1');

but forgot Route::view one rename to Route::get

like image 34
CodeToLife Avatar answered Nov 29 '25 14:11

CodeToLife



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!