mercredi 15 novembre 2017

Unable to insert an Object into Database in Laravel

I'm a laravel beginner, didn't found a solution for my problem.

I'm building a web app which shows the pagespeed of a chosen URL. I used the code from http://ift.tt/2js1EOq

I created a form to enter the urlname into database - which works fine. But for the pagespeed variable I always get this error:

Object of class PageSpeed\Insights\Service could not be converted to string

This is part of my Controller:

public function create(Request $request) {
    $pspeed = new \PageSpeed\Insights\Service();
    $pspeed->getResults('https://www.example.com');


    //Create URL
    $url = new URL;
    $url->urlname= $request->input('urlname');
    $url->pagespeed= $pspeed;

    //Save url
    $url->save();

    //Return redirect
    return redirect('/');

I put this in my migration:

   public function up()
{
    Schema::create('urls', function (Blueprint $table) {
        $table->increments('id');
        $table->string('urlname');
        $table->string('pagespeed');
        $table->timestamps();

    });
}

Maybe someone can help me with this.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2hBfcqk
via IFTTT

Aucun commentaire:

Enregistrer un commentaire