Friday, March 10, 2017

Issue to send the right data to the Blade View

When i dd() the variable after applying a filter, i get the right number of arrays. But when i pass this array to the laravel blade view i get all the records.

Heres the code.

$user = Auth::User();
            $boards = Board::all();
            $s='Tom Cruise';
            $finalarray = array();
            foreach($boards as $board)
            {
                foreach($board['owner'] as $owner )
                {
                    if($owner == $s)
                        $finalarray = array_prepend($finalarray,$board);
                }
            }
            return view('layouts.board')
            ->with(compact('user',$user))
            ->with(compact('boards',collect($finalarray)));

here is the sample data

{
        "_id" : ObjectId("58c2e21453c06144b6038f39"),
        "name" : "board",
        "description" : "with slug",
        "owner" : {
                "id" : "58bc562553c06113f130bbb3",
                "name" : "Joker"
        },
        "slug" : "board",
        "updated_at" : ISODate("2017-03-10T17:27:48.438Z"),
        "created_at" : ISODate("2017-03-10T17:27:48.438Z")
}
{
        "_id" : ObjectId("58c2e21853c06144b6038f3a"),
        "name" : "board",
        "description" : "with slug",
        "owner" : {
                "id" : "58bc562553c06113f130bbb3",
                "name" : "Joker"
        },
        "slug" : "board",
        "updated_at" : ISODate("2017-03-10T17:27:52.073Z"),
        "created_at" : ISODate("2017-03-10T17:27:52.073Z")
}
{
        "_id" : ObjectId("58c3097b53c06144b6038f40"),
        "name" : "Board by Tom Cruise",
        "description" : "afgf",
        "owner" : {
                "id" : "58c3090b53c06144b6038f3f",
                "name" : "Tom Cruise"
        },
        "slug" : "board_by_tom_cruise",
        "updated_at" : ISODate("2017-03-10T20:15:55.132Z"),
        "created_at" : ISODate("2017-03-10T20:15:55.132Z")
}

So basically i want to get all the boards where owner.name is Joker for example.

Thank you in advance.



via Aatish Kumar

Advertisement