vendredi 29 mars 2019

Laravel - Return the manipulated value from a collection

I would like to manipulate a value from a collection! I receive the stylenumber as 12345-D-002. I have to explode this on "-" to have the first part of the stylenumber.

Collection-Code from Model Order:

public static function getPicklistToday($date)
    {
        $sql = "
            SELECT
                oxid_orderarticles.OXARTNUM as style,
                sum(oxid_orderarticles.OXAMOUNT) as ANZAHL,
                oxid_orderarticles.OXSELVARIANT,
                oxid_import.imported
            FROM oxid_orderarticles
            LEFT JOIN oxid_import
                ON oxid_import.oxid = oxid_orderarticles.OXORDERID
                WHERE DATE(oxid_import.imported) = :date
            GROUP BY oxid_orderarticles.OXARTNUM
            ORDER BY oxid_orderarticles.OXARTNUM ASC
        ";
        $pick = DB::select($sql,[':date'=>$date]);

        return $pick;
    }

This is the method, which should explode the returned 'style' from the query, also in Model Order:

    public function getParentStyle()
    {

        $parent = explode("-",$this->style);

        return $parent[0];
    }

Method in the OrderController:

    //------------------------
    public function today()
    {
        $today = Order::getPicklistToday(Carbon::now()->format('Y-m-d'));

        return view('order.today',compact('today'));

    }

Part of the view today.blade.php:

    @foreach($today as $pos)
    <tr>
      <td><i class="far fa-square"></i></td>
      <td><b>x</b></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    @endforeach

I receive the following error message:
Call to undefined method stdClass::getParentStyle() (View: /var/www/html/app/resources/views/order/today.blade.php)

How should the method getParentStyle() look like to get my code running?



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

Aucun commentaire:

Enregistrer un commentaire