Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

htmlspecialchars() expects parameter 1 to be string, object given #68

Closed
Sogl opened this issue Mar 24, 2020 · 8 comments
Closed

htmlspecialchars() expects parameter 1 to be string, object given #68

Sogl opened this issue Mar 24, 2020 · 8 comments

Comments

@Sogl
Copy link

Sogl commented Mar 24, 2020

@antonkomarev Hello! I try to use this package in my project.
Took info from this wiki page: https://github.com/cybercog/laravel-eloquent-flag/wiki/Publishable-model

One line from migration:

$table->boolean('is_published')->default(0);

Model:

<?php

namespace App;

use Cog\Flag\Traits\Classic\HasPublishedFlag;
use Illuminate\Database\Eloquent\Model;
use Spatie\Tags\HasTags;

class Post extends Model
{
    use HasTags;
    use HasPublishedFlag;
    //

    protected $fillable = ['tags'];
}

Database (posts table) content:
image

My Controller:

public function index()
{
    $posts = Post::onlyNotPublished();
    //dd($posts);
    return view('manage.posts.index')->withPosts($posts);
}

And finally I got an error:
image

dd result:
image

What I'm doing wrong?

p.s. Method publish() works fine.

Laravel 5.8
laravel-eloquent-flag 5.1.2

@antonkomarev
Copy link
Member

You've got an issue in your view file accordingly to the error message. Could you show it?

@Sogl
Copy link
Author

Sogl commented Mar 24, 2020

Blade file index.blade.php:

@extends('layouts.manage')

@section('content')
    <posts-index
        :table-data="{{ $posts }}">
    </posts-index>
@endsection

Vue component index.vue:

<template>
    <fragment>
        <div class="level">
            <div class="level-left">
                <div class="level-item">
                    <h1 class="title">Администрирование постов</h1>
                </div>
            </div>
            <div class="level-right">
                <div class="level-item">
                    <a :href="route('manage.posts.create')" class="button is-link">
                        <b-icon
                            icon="plus">
                        </b-icon>
                        <span>Создать пост</span>
                    </a>
                </div>
            </div>
        </div>

        <div class="columns is-multiline">
            <div class="column">

                <b-table :data="data">

                    <template slot-scope="props">
                        <b-table-column field="title" label="Название">
                            {{ props.row.title }}
                        </b-table-column>

                        <b-table-column field="excerpt" label="Короткое">
                            {{ props.row.excerpt }}
                        </b-table-column>

                        <b-table-column field="status" label="Статус">
                            {{ props.row.status }}
                        </b-table-column>

                        <b-table-column label="Действия">
<!--                            <a class="button is-outlined is-small m-r-5" :href="route('permissions.show', props.row.id)">Просмотр</a><a :href="route('permissions.edit', props.row.id)" class="button is-small is-outlined">Редактирование</a>-->
                        </b-table-column>
                    </template>

                    <template slot="empty">
                        <section class="section">
                            <div class="content has-text-grey has-text-centered">
                                <p>
                                    <b-icon
                                            pack="far"
                                            icon="frown"
                                            size="is-xxlarge">
                                    </b-icon>
                                </p>
                                <p>Ничего нет</p>
                            </div>
                        </section>
                    </template>

                </b-table>

            </div>
        </div>
    </fragment>
</template>

<script>
    export default {
        props: ['tableData'],
        data() {
            return {
                data: this.tableData
            }
        }
    }
</script>

@antonkomarev
Copy link
Member

antonkomarev commented Mar 24, 2020

Your issue not related to this package. You cannot pass objects to Vue components this way:

:table-data="{{ $posts }}"

It awaits a string, but you giving an object to it. Have you tried this way?

:table-data="{{ json_encode($posts) }}"

Or Blade alternative:

:table-data="@json($posts)"

@Sogl
Copy link
Author

Sogl commented Mar 24, 2020

Ok, no error now, but I still can't see my posts... empty table with this line $posts = Post::onlyNotPublished();. Why?

And why basic framework staff works fine without json_encode?

@antonkomarev
Copy link
Member

Ah.... you've applied scope, but not performed an action:

Post::onlyNotPublished()->get();

@antonkomarev
Copy link
Member

Now I see that documentation isn't clear that it's just scopes. You could chain many scopes like:

Post::onlyNotPublished()->withoutNotVerified()->get();

And so on.

@antonkomarev
Copy link
Member

@Sogl thanks for pointing this out. I've updated documentation.

@Sogl
Copy link
Author

Sogl commented Mar 24, 2020

Thx...now it works without json_encode.

@Sogl Sogl closed this as completed Mar 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants