hemal
1385
4
Laravel

How to retrieve data in array object?

Posted 1 year ago by hemal

if i return this query $posts = Post::all(); reult will be like below

Array[102]
0:Object
id:1
user_id:12
content:"Ea aliquam aut ea. Soluta impedit pariatur cupiditate fugiat. Qui temporibus commodi quibusdam ratione. Doloribus hic qui totam. Voluptatibus voluptatum ex porro sit eius. Aut impedit suscipit quae optio nobis. Amet aliquam qui et dolorem omnis."
created_at:"2017-10-27 06:57:17"
updated_at:"2017-10-27 06:57:17"
user:Object
id:12
name:"Abel Altenwerth"
email:"[email protected]"
avatar:"http://localhost:8000/storage/defaults/avatars/female.png"
slug:"abel-altenwerth"
gender:0
created_at:"2017-10-27 06:57:05"
updated_at:"2017-10-27 06:57:05"
likes:Array[0]

I want to get posts that have the user object slug equivalent to what im getting throw parameters, How can I do that below code is my controller

    public function index($slug) {


        $posts = Post::all();

        return $posts;

    }

How can I retrieve posts that have slug that im getting throw parameters

Please sign in or create an account to participate in this conversation.