🔥یلدا با راکت با (( ۷۰ درصد )) تخفیف! یلدا طولانی است، اما این تخفیف نه.
مشاهده دورههادوستان من در lumen از متد map در collection استفاده میکنم ولی با ارور زیر مواجه میشم:
Call to undefined method App\Course::mapInto()
میشه راهنمایی کنید
public function toArray($request)
{
return [
'data' => $this->collection->map(function ($item) {
return [
'title' => $item->title,
'body' => $item->body,
'image' => $item->img,
];
})
];
}
public function with($request)
{
return [
'status'=>'success'
];
}
The map method iterates through the collection and passes each value to the given callback. The callback is free to modify the item and return it, thus forming a new collection of modified items:
متد map کالکشن رو پیمایش میکنه و به ازای هر یک گزینه شرط داخل کلوژر رو اعمال میکنه
اما شما یک آرایه رو بهش پاس دادید.
در عوض میتونی از متد mapWithKeys استفاده کنی:
$keyed = $collection->mapWithKeys(function ($item) {
return ['title' => $item['title']];
});
$keyed->all();
@ali.bayat
ممنون از پاسختون.ولی من تو فراخوانی یک آی دی خاص با این ارور مواجه میشم.مثلا فراخوانی یک کاربر با id=1
مثال:http://localhost:8000/api/v1/courses/1

احتمالا Instance کلاس کوئری بیلدر برگشت داده میشه و شما سعی میکنید از متد mapInto روی کوئری بیلدر استفاده کنید..
ابتدا نتایج رو به کالکشن تبدیل کنید..
آیا مایل به ارسال نوتیفیکیشن و اخبار از طرف راکت هستید ؟