简体   繁体   中英

Manipulation all model-attributes before the view

Before issuing the "Content" model, I want to search and replace all attributes for placeholders.

I use "tylercd100/laravel-placeholders" to search the placeholders and that works too!

public function processVariables()
    {
        Placeholders::setThorough(false);

        $content = \Route::current()->parameter('id');
        $arrContent = Content::findOrFail($content->id);

        $arrPlaceholders = PlaceholdersTraits::setPlaceholders($arrContent);        
        $variables = Placeholders::parse($arrContent, $arrPlaceholders);

        return $variables;
    }

Unfortunately it does not work for the output and I can not get any further.

here the error message in the ausag:

Trying to get property of non-object

enter image description here

我相信\\ Route :: current()-> parameter('id')返回字符串或整数。

With "Placeholders::parse($arrContent, $arrPlaceholders)" i get a string!

How do I convert the string to the Content-Instance (Content::findOrFail($content->id))?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM